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:com.borqs.browser.combo.BookmarksPageCallbacks.java

private void editBookmark(BrowserBookmarksAdapter adapter, int position) {
    Intent intent = new Intent(this, AddBookmarkPage.class);
    Cursor cursor = adapter.getItem(position);
    Bundle item = new Bundle();
    item.putString(BrowserContract.Bookmarks.TITLE, cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE));
    item.putString(BrowserContract.Bookmarks.URL, cursor.getString(BookmarksLoader.COLUMN_INDEX_URL));
    byte[] data = cursor.getBlob(BookmarksLoader.COLUMN_INDEX_FAVICON);
    if (data != null) {
        item.putParcelable(BrowserContract.Bookmarks.FAVICON,
                BitmapFactory.decodeByteArray(data, 0, data.length));
    }/*from w  w  w .j  a v  a2 s.c om*/
    item.putLong(BrowserContract.Bookmarks._ID, cursor.getLong(BookmarksLoader.COLUMN_INDEX_ID));
    item.putLong(BrowserContract.Bookmarks.PARENT, cursor.getLong(BookmarksLoader.COLUMN_INDEX_PARENT));
    intent.putExtra(AddBookmarkPage.EXTRA_EDIT_BOOKMARK, item);
    intent.putExtra(AddBookmarkPage.EXTRA_IS_FOLDER,
            cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) == 1);
    startActivity(intent);
}

From source file:com.tct.email.provider.EmailMessageCursor.java

public EmailMessageCursor(final Context c, final Cursor cursor, final String htmlColumn,
        final String textColumn) {
    super(cursor);
    mHtmlColumnIndex = cursor.getColumnIndex(htmlColumn);
    mTextColumnIndex = cursor.getColumnIndex(textColumn);
    final int cursorSize = cursor.getCount();
    mHtmlParts = new SparseArray<String>(cursorSize);
    mTextParts = new SparseArray<String>(cursorSize);
    //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
    mHtmlLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_HTML_LINKIFY);
    mHtmlLinkifyParts = new SparseArray<String>(cursorSize);
    mTextLinkifyColumnIndex = cursor.getColumnIndex(UIProvider.MessageColumns.BODY_TEXT_LINKIFY);
    mTextLinkifyParts = new SparseArray<String>(cursorSize);
    //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E

    final ContentResolver cr = c.getContentResolver();

    while (cursor.moveToNext()) {
        final int position = cursor.getPosition();
        final long messageId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
        // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046  MOD_S
        InputStream htmlIn = null;
        InputStream textIn = null;
        try {/*from w  w w  .j  a  v a 2 s.co  m*/
            if (mHtmlColumnIndex != -1) {
                final Uri htmlUri = Body.getBodyHtmlUriForMessageWithId(messageId);
                //WARNING: Actually openInput will used 2 PIPE(FD) to connect,but if some exception happen during connect,
                //such as fileNotFoundException,maybe the connection will not be closed. just a try!!!
                htmlIn = cr.openInputStream(htmlUri);
                final String underlyingHtmlString;
                try {
                    underlyingHtmlString = IOUtils.toString(htmlIn);
                } finally {
                    htmlIn.close();
                    htmlIn = null;
                }
                //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_S
                final String sanitizedHtml = HtmlSanitizer.sanitizeHtml(underlyingHtmlString);
                mHtmlParts.put(position, sanitizedHtml);
                //TS: zhaotianyong 2015-04-05 EMAIL BUGFIX_964325 MOD_E
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
                //NOTE: add links for sanitized html
                if (!TextUtils.isEmpty(sanitizedHtml)) {
                    final String linkifyHtml = com.tct.mail.utils.Linkify.addLinks(sanitizedHtml);
                    mHtmlLinkifyParts.put(position, linkifyHtml);
                } else {
                    mHtmlLinkifyParts.put(position, "");
                }
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find html body for message %d", messageId);
        } catch (final OutOfMemoryError oom) {
            LogUtils.v(LogUtils.TAG, oom,
                    "Terrible,OOM happen durning query EmailMessageCursor in bodyHtml,current message %d",
                    messageId);
            mHtmlLinkifyParts.put(position, "");
        }
        try {
            if (mTextColumnIndex != -1) {
                final Uri textUri = Body.getBodyTextUriForMessageWithId(messageId);
                textIn = cr.openInputStream(textUri);
                final String underlyingTextString;
                try {
                    underlyingTextString = IOUtils.toString(textIn);
                } finally {
                    textIn.close();
                    textIn = null;
                }
                mTextParts.put(position, underlyingTextString);
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_S
                //NOTE: add links for underlying text string
                if (!TextUtils.isEmpty(underlyingTextString)) {
                    final SpannableString spannable = new SpannableString(underlyingTextString);
                    Linkify.addLinks(spannable,
                            Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
                    final String linkifyText = Html.toHtml(spannable);
                    mTextLinkifyParts.put(position, linkifyText);
                } else {
                    mTextLinkifyParts.put(position, "");
                }
                //TS: jian.xu 2015-11-03 EMAIL BUGFIX-845079 ADD_E
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find text body for message %d", messageId);
        } catch (final OutOfMemoryError oom) {
            LogUtils.v(LogUtils.TAG, oom,
                    "Terrible,OOM happen durning query EmailMessageCursor in bodyText,current message %d",
                    messageId);
            mTextLinkifyParts.put(position, "");
        }
        //NOTE:Remember that this just a protective code,for better release Not used Resources.
        if (htmlIn != null) {
            try {
                htmlIn.close();
            } catch (IOException e1) {
                LogUtils.v(LogUtils.TAG, e1, "IOException happen while close the htmlInput connection ");
            }
        }
        if (textIn != null) {
            try {
                textIn.close();
            } catch (IOException e2) {
                LogUtils.v(LogUtils.TAG, e2, "IOException happen while close the textInput connection ");
            }
        } // TS: chao.zhang 2015-09-14 EMAIL BUGFIX-1039046  MOD_E
    }
    cursor.moveToPosition(-1);
}

From source file:com.ruuhkis.cookies.CookieSQLSource.java

/**
 * Updates cookie if it already exists else adds new cookie tot the table
 * @param cookie/*  w  w w.ja va 2s.  c om*/
 */

public void addCookie(Cookie cookie) {
    long cookieId = -1;

    Cursor cursor = db.query(CookieSQLHelper.COOKIE_TABLE_NAME, null, CookieSQLHelper.COLUMN_NAME + "=?",
            new String[] { cookie.getName() }, null, null, null);

    ContentValues cookieValues = new ContentValues();
    cookieValues.put(CookieSQLHelper.COLUMN_COMMENT, cookie.getComment());
    cookieValues.put(CookieSQLHelper.COLUMN_COMMENT_URL, cookie.getCommentURL());
    cookieValues.put(CookieSQLHelper.COLUMN_DOMAIN, cookie.getDomain());
    Date date = cookie.getExpiryDate();
    cookieValues.put(CookieSQLHelper.COLUMN_EXPIRY_DATE, date != null ? date.getTime() : -1);
    cookieValues.put(CookieSQLHelper.COLUMN_NAME, cookie.getName());
    cookieValues.put(CookieSQLHelper.COLUMN_PATH, cookie.getPath());

    cookieValues.put(CookieSQLHelper.COLUMN_PERSISTENT, cookie.isPersistent() ? 1 : 0);
    cookieValues.put(CookieSQLHelper.COLUMN_SECURE, cookie.isSecure() ? 1 : 0);
    cookieValues.put(CookieSQLHelper.COLUMN_VALUE, cookie.getValue());
    cookieValues.put(CookieSQLHelper.COLUMN_VERSION, cookie.getVersion());

    if (cursor.moveToFirst()) {
        cookieId = cursor.getLong(cursor.getColumnIndex(CookieSQLHelper.COLUMN_COOKIE_ID));
        db.update(CookieSQLHelper.COOKIE_TABLE_NAME, cookieValues, CookieSQLHelper.COLUMN_ID + "=?",
                new String[] { Long.toString(cookieId) });
        db.delete(CookieSQLHelper.PORT_TABLE_NAME, CookieSQLHelper.COLUMN_COOKIE_ID + "=?",
                new String[] { Long.toString(cookieId) });
    } else {
        cookieId = db.insert(CookieSQLHelper.COOKIE_TABLE_NAME, null, cookieValues);
    }

    if (cookieId != -1) {

        int[] ports = cookie.getPorts();
        if (ports != null) {
            for (int i = 0; i < ports.length; i++) {
                ContentValues portValues = new ContentValues();
                portValues.put(CookieSQLHelper.COLUMN_COOKIE_ID, cookieId);
                portValues.put(CookieSQLHelper.COLUMN_PORT, ports[i]);
                db.insert(CookieSQLHelper.PORT_TABLE_NAME, null, portValues);
            }
        }
    } else {
        Log.e(TAG, "id = -1");
    }
    cursor.close();
}

From source file:ch.ethz.twimight.net.tds.TDSRequestMessage.java

/**
 * creates JSONObject to push Statistics to the TDS
 * // www  . j  a  v  a 2 s . co m
 * @param
 * @return JSON Object
 * @throws JSONException
 */
public void createStatisticObject(Cursor stats, long follCount) throws JSONException {

    if (stats != null) {
        statisticObject = new JSONObject();
        JSONArray statisticArray = new JSONArray();

        while (!stats.isAfterLast()) {

            JSONObject row = new JSONObject();
            row.put("latitude", Double
                    .toString(stats.getDouble(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_LAT))));
            row.put("longitude", Double
                    .toString(stats.getDouble(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_LNG))));
            row.put("accuracy", Integer
                    .toString(stats.getInt(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_ACCURACY))));
            row.put("provider",
                    stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_PROVIDER)));
            row.put("timestamp",
                    Long.toString(stats.getLong(stats.getColumnIndex(StatisticsDBHelper.KEY_TIMESTAMP))));
            row.put("network", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_NETWORK)));
            row.put("event", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_EVENT)));
            row.put("link", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_LINK)));
            row.put("isDisaster",
                    Integer.toString(stats.getInt(stats.getColumnIndex(StatisticsDBHelper.KEY_ISDISASTER))));
            row.put("followers_count", follCount);
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            row.put("dis_mode_used",
                    Preferences.getBoolean(context, R.string.pref_key_disastermode_has_been_used, false));

            statisticArray.put(row);
            stats.moveToNext();
        }
        stats.close();

        statisticObject.put("content", statisticArray);

    }
}

From source file:com.piusvelte.sonet.core.SonetCreatePost.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();/*from w ww  . ja  va2 s.  co  m*/
    if (intent != null) {
        String action = intent.getAction();
        if ((action != null) && action.equals(Intent.ACTION_SEND)) {
            if (intent.hasExtra(Intent.EXTRA_STREAM))
                getPhoto((Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM));
            if (intent.hasExtra(Intent.EXTRA_TEXT)) {
                final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
                mMessage.setText(text);
                mCount.setText(Integer.toString(text.length()));
            }
            chooseAccounts();
        } else {
            Uri data = intent.getData();
            if ((data != null) && data.toString().contains(Accounts.getContentUri(this).toString())) {
                // default to the account passed in, but allow selecting additional accounts
                Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                        new String[] { Accounts._ID, Accounts.SERVICE }, Accounts._ID + "=?",
                        new String[] { data.getLastPathSegment() }, null);
                if (account.moveToFirst())
                    mAccountsService.put(account.getLong(0), account.getInt(1));
                account.close();
            } else if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
                // check if a photo path was passed and prompt user to select the account
                setPhoto(intent.getStringExtra(Widgets.INSTANT_UPLOAD));
                chooseAccounts();
            }
        }
    }
}

From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java

@Override
public Uri insert(final Uri uri, final ContentValues values) {
    try {/*from  www  .  j  a va 2s .  co  m*/
        final int tableId = getTableId(uri);
        final String table = getTableNameById(tableId);
        switch (tableId) {
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
        case TABLE_ID_DIRECT_MESSAGES:
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRIES:
            return null;
        }
        if (table == null)
            return null;
        final long rowId;
        if (tableId == TABLE_ID_CACHED_USERS) {
            final Expression where = Expression.equals(CachedUsers.USER_ID,
                    values.getAsLong(CachedUsers.USER_ID));
            mDatabaseWrapper.update(table, values, where.getSQL(), null);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_SEARCH_HISTORY) {
            values.put(SearchHistory.RECENT_QUERY, System.currentTimeMillis());
            final Expression where = Expression.equalsArgs(SearchHistory.QUERY);
            final String[] args = { values.getAsString(SearchHistory.QUERY) };
            mDatabaseWrapper.update(table, values, where.getSQL(), args);
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
        } else if (tableId == TABLE_ID_CACHED_RELATIONSHIPS) {
            final long accountId = values.getAsLong(CachedRelationships.ACCOUNT_ID);
            final long userId = values.getAsLong(CachedRelationships.USER_ID);
            final Expression where = Expression.and(
                    Expression.equals(CachedRelationships.ACCOUNT_ID, accountId),
                    Expression.equals(CachedRelationships.USER_ID, userId));
            if (mDatabaseWrapper.update(table, values, where.getSQL(), null) > 0) {
                final String[] projection = { CachedRelationships._ID };
                final Cursor c = mDatabaseWrapper.query(table, projection, where.getSQL(), null, null, null,
                        null);
                if (c.moveToFirst()) {
                    rowId = c.getLong(0);
                } else {
                    rowId = 0;
                }
                c.close();
            } else {
                rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values,
                        SQLiteDatabase.CONFLICT_IGNORE);
            }
        } else if (shouldReplaceOnConflict(tableId)) {
            rowId = mDatabaseWrapper.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_REPLACE);
        } else {
            rowId = mDatabaseWrapper.insert(table, null, values);
        }
        onDatabaseUpdated(tableId, uri);
        onNewItemsInserted(uri, tableId, values, rowId);
        return Uri.withAppendedPath(uri, String.valueOf(rowId));
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:edu.cens.loci.provider.LociDbUtils.java

public int delete(SQLiteDatabase db, Cursor c) {
    long dataId = c.getLong(DataDeleteQuery._ID);
    //long placeId = c.getLong(DataDeleteQuery.PLACE_ID);
    mSelectionArgs1[0] = String.valueOf(dataId);
    int count = db.delete(Tables.DATA, Data._ID + "=?", mSelectionArgs1);
    return count;
}

From source file:se.lu.nateko.edca.BackboneSvc.java

/**
 * Deactivates all layers by removing the "active" factor from
 * the layer mode.//from w  ww.j a v  a  2 s  . co m
 */
public void deactivateLayers() {
    Log.d(TAG, "deactivateLayers() called.");
    Cursor activeLayers = getSQLhelper().fetchData(LocalSQLDBhelper.TABLE_LAYER,
            LocalSQLDBhelper.KEY_LAYER_COLUMNS, LocalSQLDBhelper.ALL_RECORDS, null, true);
    getActiveActivity().startManagingCursor(activeLayers);

    while (activeLayers.moveToNext()) { // As long as there's another row:
        if (activeLayers.getInt(2) % LocalSQLDBhelper.LAYER_MODE_ACTIVE == 0) {// If the layer is set to "active", then deactivate;
            getSQLhelper().updateData(LocalSQLDBhelper.TABLE_LAYER, activeLayers.getLong(0),
                    LocalSQLDBhelper.KEY_LAYER_ID, new String[] { LocalSQLDBhelper.KEY_LAYER_USEMODE },
                    new String[] {
                            String.valueOf(activeLayers.getInt(2) / LocalSQLDBhelper.LAYER_MODE_ACTIVE) });
        }
    }
}

From source file:cn.code.notes.gtask.remote.GTaskManager.java

private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
    if (mCancelled) {
        return;/*from   w ww .  j a  va 2s.  c  o m*/
    }

    MetaData meta;
    switch (syncType) {
    case Node.SYNC_ACTION_ADD_LOCAL:
        addLocalNode(node);
        break;
    case Node.SYNC_ACTION_ADD_REMOTE:
        addRemoteNode(node, c);
        break;
    case Node.SYNC_ACTION_DEL_LOCAL:
        meta = mMetaHashMap.get(c.getString(SqlNote.GTASK_ID_COLUMN));
        if (meta != null) {
            GTaskClient.getInstance().deleteNode(meta);
        }
        mLocalDeleteIdMap.add(c.getLong(SqlNote.ID_COLUMN));
        break;
    case Node.SYNC_ACTION_DEL_REMOTE:
        meta = mMetaHashMap.get(node.getGid());
        if (meta != null) {
            GTaskClient.getInstance().deleteNode(meta);
        }
        GTaskClient.getInstance().deleteNode(node);
        break;
    case Node.SYNC_ACTION_UPDATE_LOCAL:
        updateLocalNode(node, c);
        break;
    case Node.SYNC_ACTION_UPDATE_REMOTE:
        updateRemoteNode(node, c);
        break;
    case Node.SYNC_ACTION_UPDATE_CONFLICT:
        // merging both modifications maybe a good idea
        // right now just use local update simply
        updateRemoteNode(node, c);
        break;
    case Node.SYNC_ACTION_NONE:
        break;
    case Node.SYNC_ACTION_ERROR:
    default:
        throw new ActionFailureException("unkown sync action type");
    }
}

From source file:mobisocial.bento.todo.io.BentoManager.java

synchronized public void loadBentoList() {
    long prevFeedId = -1;
    String[] projection = new String[] { DbObj.COL_ID, DbObj.COL_FEED_ID };
    Uri uri = Musubi.uriForDir(DbThing.OBJECT);
    String selection = "type = ?";
    String[] selectionArgs = new String[] { TYPE_TODOBENTO };
    String sortOrder = DbObj.COL_FEED_ID + " asc, " + DbObj.COL_LAST_MODIFIED_TIMESTAMP + " asc";

    Cursor c = mMusubi.getContext().getContentResolver().query(uri, projection, selection, selectionArgs,
            sortOrder);/*from  w ww  . ja  va  2  s .  co m*/

    ArrayList<BentoListItem> tmpList = new ArrayList<BentoListItem>();
    if (c != null && c.moveToFirst()) {
        mBentoList = new ArrayList<BentoListItem>();

        for (int i = 0; i < c.getCount(); i++) {
            BentoListItem item = new BentoListItem();
            item.bento = new Bento();

            DbObj dbObj = mMusubi.objForCursor(c);
            LatestObj latestObj = null;

            latestObj = fetchLatestObj(c.getLong(0));
            if (latestObj != null && latestObj.json.has(STATE)) {
                JSONObject stateObj = latestObj.json.optJSONObject(STATE);
                if (fetchBentoObj(stateObj, item.bento)) {
                    item.objUri = dbObj.getUri();
                    item.feedId = c.getLong(1);
                    if (DEBUG) {
                        Log.d(TAG, item.objUri.toString());
                        Log.d(TAG, item.feedId + "");
                    }

                    // count number of todo
                    ArrayList<TodoListItem> todoList = new ArrayList<TodoListItem>();
                    if (fetchTodoListObj(stateObj, todoList)) {
                        item.bento.numberOfTodo = todoList.size();
                        tmpList.add(0, item);
                    }

                    // load members
                    fetchMemberNames(item.feedId);
                }
            }
            c.moveToNext();
        }
    }
    c.close();

    // insert dividers
    if (tmpList.size() > 0) {
        for (int j = 0; j < tmpList.size(); j++) {
            BentoListItem item = tmpList.get(j);
            if (prevFeedId != item.feedId) {
                BentoListItem divider = new BentoListItem();
                divider.enabled = false;
                divider.feedId = item.feedId;
                mBentoList.add(divider);

                prevFeedId = item.feedId;
            }
            mBentoList.add(item);
        }
    }

    if (DEBUG) {
        Log.d(TAG, "tmpList:" + tmpList.size() + " mBentoList:" + mBentoList.size());
    }
}