List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:se.lu.nateko.edca.svc.GeoHelper.java
@Override protected void onPostExecute(GeoHelper result) { Log.d(TAG, "onPostExecute(GeoHelper) called."); if (mRwMode != RWMODE_UPLOAD) stopWatchingExternalStorage(); // No more need to watch for storage state changes. if (mSuccess) { if (mRwMode == RWMODE_READ) { mService.deactivateLayers(); Cursor modeCursor = mService.getSQLhelper().fetchData(LocalSQLDBhelper.TABLE_LAYER, LocalSQLDBhelper.KEY_LAYER_COLUMNS, mRowId, null, false); mService.getActiveActivity().startManagingCursor(modeCursor); if (modeCursor.moveToFirst()) { mService.getSQLhelper().updateData(LocalSQLDBhelper.TABLE_LAYER, modeCursor.getLong(0), LocalSQLDBhelper.KEY_LAYER_ID, new String[] { LocalSQLDBhelper.KEY_LAYER_USEMODE }, new String[] { String.valueOf(modeCursor.getLong(2) * LocalSQLDBhelper.LAYER_MODE_ACTIVE) }); // Add the "Active" mode to the current mode. mService.updateLayoutOnState(); }//ww w . j a v a 2 s . c o m mService.showToast(R.string.layerviewer_uploadtoast_readsuccess); } else if (mRwMode == RWMODE_UPLOAD) { mService.stopAnimation(); // Stop the animation, showing that a web communicating thread is no longer active. mService.showToast(R.string.layerviewer_uploadtoast_uploadsuccess); } else { // Successful write operation. Log.i(TAG, "Write operation successful."); Cursor modeCursor = mService.getSQLhelper().fetchData(LocalSQLDBhelper.TABLE_LAYER, LocalSQLDBhelper.KEY_LAYER_COLUMNS, LocalSQLDBhelper.ALL_RECORDS, LocalSQLDBhelper.KEY_LAYER_NAME + " = " + "\"" + mGeoLayer.getName() + "\"", false); mService.getActiveActivity().startManagingCursor(modeCursor); if (modeCursor.moveToFirst()) { if (modeCursor.getLong(2) % LocalSQLDBhelper.LAYER_MODE_STORE != 0) // Don't add the stored mode more than once. mService.getSQLhelper().updateData(LocalSQLDBhelper.TABLE_LAYER, modeCursor.getLong(0), LocalSQLDBhelper.KEY_LAYER_ID, new String[] { LocalSQLDBhelper.KEY_LAYER_USEMODE }, new String[] { String .valueOf(modeCursor.getLong(2) * LocalSQLDBhelper.LAYER_MODE_STORE) }); // Add the "Stored" mode to the current mode. mService.updateLayoutOnState(); mService.showToast(R.string.layerviewer_uploadtoast_writesuccess); } else { Log.e(TAG, "No such layer."); } } } else { if (mRwMode == RWMODE_READ) mService.showToast(R.string.layerviewer_uploadtoast_readfail); else if (mRwMode == RWMODE_WRITE && mFileConflict) { /* If write failed because of a file conflict, ask to overwrite the data. */ new AlertDialog.Builder(mService.getActiveActivity()).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.layerviewer_overwritealert_title) .setMessage(R.string.layerviewer_overwritealert_msg) .setPositiveButton(R.string.layerviewer_overwritealert_confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mService.makeSaveOperation(GeoHelper.RWMODE_OVERWRITE); dialog.dismiss(); } }) .setNegativeButton(R.string.layerviewer_overwritealert_decline, null).show(); } else if (mRwMode == RWMODE_UPLOAD) { /* If an upload failed, ask to store the data locally. */ mService.stopAnimation(); // Stop the animation, showing that a web communicating thread is no longer active. mService.clearConnection(false); // Clear the failed connection without reporting (specialized report below). new AlertDialog.Builder(mService.getActiveActivity()).setIcon(android.R.drawable.ic_menu_upload) .setTitle(R.string.layerviewer_uploaddialog_title) .setMessage(R.string.layerviewer_uploaddialog_msg) .setPositiveButton(R.string.layerviewer_uploaddialog_confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mService.makeSaveOperation(GeoHelper.RWMODE_WRITE); dialog.dismiss(); } }) .setNegativeButton(R.string.layerviewer_uploaddialog_decline, null).show(); } else mService.showToast(R.string.layerviewer_uploadtoast_writefail); } /* Reactivate the upload button and set the flag in the BackboneSvc. */ mService.setUploading(false); if (mService.getActiveActivity().getLocalClassName().equalsIgnoreCase("LayerViewer")) ((LayerViewer) mService.getActiveActivity()).setLayout_UploadButton(true, false); super.onPostExecute(result); }
From source file:com.android.contacts.common.model.ContactLoader.java
/** * Loads groups meta-data for all groups associated with all constituent raw contacts' * accounts.//from ww w .java 2 s.c o m */ private void loadGroupMetaData(Contact result) { StringBuilder selection = new StringBuilder(); ArrayList<String> selectionArgs = new ArrayList<String>(); final HashSet<AccountKey> accountsSeen = new HashSet<>(); for (RawContact rawContact : result.getRawContacts()) { final String accountName = rawContact.getAccountName(); final String accountType = rawContact.getAccountTypeString(); final String dataSet = rawContact.getDataSet(); final AccountKey accountKey = new AccountKey(accountName, accountType, dataSet); if (accountName != null && accountType != null && !accountsSeen.contains(accountKey)) { accountsSeen.add(accountKey); if (selection.length() != 0) { selection.append(" OR "); } selection.append("(" + Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=?"); selectionArgs.add(accountName); selectionArgs.add(accountType); if (dataSet != null) { selection.append(" AND " + Groups.DATA_SET + "=?"); selectionArgs.add(dataSet); } else { selection.append(" AND " + Groups.DATA_SET + " IS NULL"); } selection.append(")"); } } final ImmutableList.Builder<GroupMetaData> groupListBuilder = new ImmutableList.Builder<GroupMetaData>(); final Cursor cursor = getContext().getContentResolver().query(Groups.CONTENT_URI, GroupQuery.COLUMNS, selection.toString(), selectionArgs.toArray(new String[0]), null); if (cursor != null) { try { while (cursor.moveToNext()) { final String accountName = cursor.getString(GroupQuery.ACCOUNT_NAME); final String accountType = cursor.getString(GroupQuery.ACCOUNT_TYPE); final String dataSet = cursor.getString(GroupQuery.DATA_SET); final long groupId = cursor.getLong(GroupQuery.ID); final String title = cursor.getString(GroupQuery.TITLE); final boolean defaultGroup = cursor.isNull(GroupQuery.AUTO_ADD) ? false : cursor.getInt(GroupQuery.AUTO_ADD) != 0; final boolean favorites = cursor.isNull(GroupQuery.FAVORITES) ? false : cursor.getInt(GroupQuery.FAVORITES) != 0; groupListBuilder.add(new GroupMetaData(accountName, accountType, dataSet, groupId, title, defaultGroup, favorites)); } } finally { cursor.close(); } } result.setGroupMetaData(groupListBuilder.build()); }
From source file:mobisocial.bento.ebento.io.EventManager.java
synchronized public void loadEventList() { 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_EBENTO }; String sortOrder = DbObj.COL_FEED_ID + " asc, " + DbObj.COL_LAST_MODIFIED_TIMESTAMP + " asc"; Cursor c = mMusubi.getContext().getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);/*ww w.j a v a 2 s.c om*/ ArrayList<EventListItem> tmpList = new ArrayList<EventListItem>(); if (c != null && c.moveToFirst()) { mEventList = new ArrayList<EventListItem>(); for (int i = 0; i < c.getCount(); i++) { EventListItem item = new EventListItem(); item.event = new Event(); 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 (fetchEventObj(dbObj.getUri(), stateObj, item.event)) { item.objUri = dbObj.getUri(); item.feedId = c.getLong(1); if (DEBUG) { Log.d(TAG, item.objUri.toString()); Log.d(TAG, item.feedId + ""); } 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++) { EventListItem item = tmpList.get(j); if (prevFeedId != item.feedId) { EventListItem divider = new EventListItem(); divider.enabled = false; divider.feedId = item.feedId; mEventList.add(divider); prevFeedId = item.feedId; } mEventList.add(item); } } if (DEBUG) { Log.d(TAG, "tmpList:" + tmpList.size() + " mEventList:" + mEventList.size()); } }
From source file:com.raspi.chatapp.util.storage.MessageHistory.java
public MessageArrayContent[] getMessages(String buddyId, int amount, int offset, boolean reverse) { //Log.d("DATABASE", "Getting messages"); SQLiteDatabase db = mDbHelper.getReadableDatabase(); String[] columns = new String[] { MessageHistoryContract.MessageEntry.COLUMN_NAME_BUDDY_ID, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_TYPE, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_CONTENT, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_URL, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_STATUS, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_TIMESTAMP, MessageHistoryContract.MessageEntry._ID, MessageHistoryContract.MessageEntry.COLUMN_NAME_OTHERS_ID }; Cursor messages = db.query(buddyId, columns, null, null, null, null, MessageHistoryContract.MessageEntry.COLUMN_NAME_MESSAGE_TIMESTAMP + " DESC", offset + "," + amount); if (reverse)//from w ww . j a v a 2 s .c o m messages.moveToFirst(); else messages.moveToLast(); int messageCount = messages.getCount(); MessageArrayContent[] result = new MessageArrayContent[messageCount]; int i = 0; if (messages.getCount() > 0) do { String from = messages.getString(0); SharedPreferences preferences = context.getSharedPreferences(Constants.PREFERENCES, 0); String me = preferences.getString(Constants.USERNAME, ""); String type = messages.getString(1); String content = messages.getString(2); String url = messages.getString(3); int progress = 0; String status = messages.getString(4); long time = messages.getLong(5); long _ID = messages.getLong(6); long othersId = messages.getLong(7); switch (type) { case (MessageHistory.TYPE_TEXT): result[i] = new TextMessage(!me.equals(from), content, time, status, _ID, othersId); // if (((TextMessage) result[i]).left) // updateMessageStatus(from, _ID, STATUS_READ); break; case (MessageHistory.TYPE_IMAGE): try { JSONArray contentJSON = new JSONArray(content); result[i] = new ImageMessage(!me.equals(from), //left contentJSON.getString(0), //File contentJSON.getString(1), //description url, //url progress, //progress time, //timeStamp status, //status _ID, //_ID buddyId, //buddyID othersId); //othersId } catch (Exception e) { e.printStackTrace(); } break; } i++; } while (messages.move((reverse) ? 1 : -1)); db.close(); messages.close(); return result; }
From source file:edu.cens.loci.provider.LociDbUtils.java
public ArrayList<LociVisit> getBaseVisits(long startTime, long endTime) { ArrayList<LociVisit> visits = new ArrayList<LociVisit>(); final SQLiteDatabase db = mDbHelper.getReadableDatabase(); String selection = (Visits.EXIT + ">=" + startTime + " AND " + Visits.ENTER + "<=" + endTime); Cursor cursor = db.query(Tables.VISITS, null, selection, null, null, null, null); if (cursor.moveToFirst()) { do {/* w w w . java 2s . c o m*/ long visitId = cursor.getLong(cursor.getColumnIndex(Visits._ID)); long placeId = cursor.getLong(cursor.getColumnIndex(Visits.PLACE_ID)); int type = cursor.getInt(cursor.getColumnIndex(Visits.TYPE)); long enter = cursor.getLong(cursor.getColumnIndex(Visits.ENTER)); long exit = cursor.getLong(cursor.getColumnIndex(Visits.EXIT)); //Log.d(TAG, String.format("visitId=%d placeId=%d type=%d enter=%d exit=%d", visitId, placeId, type, enter, exit)); visits.add(new LociVisit(visitId, placeId, type, enter, exit)); } while (cursor.moveToNext()); } cursor.close(); return visits; }
From source file:mobisocial.socialkit.musubi.Musubi.java
public DbObj objForId(long localId) { Cursor cursor = mContext.getContentResolver().query(DbObj.OBJ_URI, new String[] { DbObj.COL_APP_ID, DbObj.COL_TYPE, DbObj.COL_STRING_KEY, DbObj.COL_JSON, DbObj.COL_RAW, DbObj.COL_IDENTITY_ID, DbObj.COL_UNIVERSAL_HASH, DbObj.COL_FEED_ID, DbObj.COL_INT_KEY, DbObj.COL_TIMESTAMP, DbObj.COL_PARENT_ID }, DbObj.COL_ID + " = ?", new String[] { String.valueOf(localId) }, null); try {/*from ww w.j a va 2 s .c om*/ if (cursor == null || !cursor.moveToFirst()) { Log.w(TAG, "Obj " + localId + " not found."); return null; } final String appId = cursor.getString(0); final String type = cursor.getString(1); final String name = cursor.getString(2); final JSONObject json = new JSONObject(cursor.getString(3)); final byte[] raw = cursor.isNull(4) ? null : cursor.getBlob(4); final long senderId = cursor.getLong(5); final byte[] hash = cursor.getBlob(6); final long feedId = cursor.getLong(7); final Integer intKey = cursor.isNull(8) ? null : cursor.getInt(8); final long timestamp = cursor.getLong(9); Long parentId = cursor.isNull(10) ? null : cursor.getLong(10); return new DbObj(this, appId, feedId, parentId, senderId, localId, type, json, raw, intKey, name, timestamp, hash); } catch (JSONException e) { Log.e(TAG, "Couldn't parse obj.", e); return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.triarc.sync.SyncAdapter.java
@SuppressLint("NewApi") private JSONObject getVersions(SyncType type, SyncTypeCollection collection, MutableBoolean hasUpdates) { JSONObject changeSet = new JSONObject(); JSONArray entityVersions = new JSONArray(); SQLiteDatabase openDatabase = null;//ww w. j av a2s .c om Cursor query = null; try { changeSet.put("entityVersions", entityVersions); openDatabase = openDatabase(collection); query = openDatabase.query(type.getName(), new String[] { "_id", "_timestamp", "__internalTimestamp", "__state" }, null, null, null, null, "__internalTimestamp ASC"); while (query.moveToNext()) { syncResult.stats.numEntries++; JSONObject jsonObject = new JSONObject(); int fieldType = query.getType(0); String id = query.getString(0); String queryId = this.getQueryId(fieldType, id); jsonObject.put("id", id); jsonObject.put("timestamp", query.getLong(1)); jsonObject.put("clientTimestamp", query.getLong(2)); int state = query.getInt(3); if (state != UNCHANGED) { hasUpdates.setValue(true); } if (state == ADDED || state == UPDATED) { appendEntity(type, openDatabase, jsonObject, queryId); } jsonObject.put("state", state); entityVersions.put(jsonObject); } } catch (Exception e) { syncResult.stats.numIoExceptions++; syncResult.stats.numSkippedEntries++; syncResult.databaseError = true; e.printStackTrace(); sendLogs(); } finally { if (query != null) query.close(); if (openDatabase != null && openDatabase.isOpen()) closeDb(collection.getName()); } return changeSet; }
From source file:edu.cens.loci.provider.LociDbUtils.java
/** * Delete data row by row so that fixing of primaries etc work correctly. *///from w w w . ja v a 2s. c o m public int deleteData(String selection, String[] selectionArgs, boolean callerIsSyncAdapter) { int count = 0; final SQLiteDatabase db = mDbHelper.getReadableDatabase(); // Note that the query will return data according to the access restrictions, // so we don't need to worry about deleting data we don't have permission to read. Cursor c = db.query(Tables.DATA, DataDeleteQuery.COLUMNS, selection, selectionArgs, null, null, null); try { while (c.moveToNext()) { long placeId = c.getLong(DataDeleteQuery.PLACE_ID); String mimeType = c.getString(DataDeleteQuery.MIMETYPE); DataRowHandler rowHandler = getDataRowHandler(mimeType); count += rowHandler.delete(db, c); if (!callerIsSyncAdapter) { setPlaceDirty(placeId); } } } finally { c.close(); } return count; }
From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java
/** * Handle updates to a controller tabhost based on a query result stored in a cursor. *//*from w ww. j a v a2 s. com*/ private void updateAllControllerTabs(Ctlr cntl, Cursor cursor) { try { // Header Area cntl.mTitleString = cursor.getString(ControllersQuery.TITLE); cntl.mSubtitle = cursor.getString(ControllersQuery.WAN_URL); cntl.mTimestamp = cursor.getLong(ControllersQuery.LAST_UPDATED); Date timestampD = new Date(cntl.mTimestamp); SimpleDateFormat formatter = new SimpleDateFormat("M/d/yy h:mm a"); String timestampS = formatter.format(timestampD); cntl.mTitleView.setText(timestampS); cntl.mSubtitleView.setText(cntl.mSubtitle); try { cntl.mControllerId = Integer.valueOf(cursor.getString(ControllersQuery._ID)); } catch (NumberFormatException e) { cntl.mControllerId = -1; } if (controllerUpdateFlag) { Uri newProbeUri = Data.buildQueryPDataAtUri(cntl.mControllerId, cntl.mTimestamp); Uri newOutletUri = Data.buildQueryODataAtUri(cntl.mControllerId, cntl.mTimestamp); cntl.mProbesFragment.reloadSelf(newProbeUri); cntl.mOutletsFragment.reloadSelf(newOutletUri); controllerUpdateFlag = false; } // AnalyticsUtils.getInstance(this).trackPageView("/Sessions/" + cntl.mTitleString); updateWorkspaceHeader(cntl.index); } finally { // cursor.close(); closed a level above } }
From source file:edu.cens.loci.provider.LociDbUtils.java
/** * //from w ww . ja va 2 s . com * @param cursor * @return */ private ArrayList<LociVisitWifi> cursor2visitwifi(Cursor cursor) { ArrayList<LociVisitWifi> visits = new ArrayList<LociVisitWifi>(); if (cursor.moveToFirst()) { do { long visitId = cursor.getLong(cursor.getColumnIndex(Visits._ID)); long placeId = cursor.getLong(cursor.getColumnIndex(Visits.PLACE_ID)); int type = cursor.getInt(cursor.getColumnIndex(Visits.TYPE)); long enter = cursor.getLong(cursor.getColumnIndex(Visits.ENTER)); long exit = cursor.getLong(cursor.getColumnIndex(Visits.EXIT)); if (type != Places.TYPE_WIFI) { MyLog.e(LociConfig.D.ERROR, TAG, "cursor2visitwifi: type is not wifi."); continue; } LociWifiFingerprint wifi = null; try { wifi = new LociWifiFingerprint(cursor.getString(cursor.getColumnIndex(Visits.EXTRA1))); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "cursor2visitwifi : EXTRA1 (wifi fingerprint) json error."); } ArrayList<RecognitionResult> recognitions = new ArrayList<RecognitionResult>(); try { JSONArray jArr = new JSONArray(cursor.getString(cursor.getColumnIndex(Visits.EXTRA2))); for (int i = 0; i < jArr.length(); i++) { JSONObject jObj = jArr.getJSONObject(i); RecognitionResult result = new RecognitionResult(jObj.getLong("time"), jObj.getInt("place_id"), jObj.getInt("figerprint_id"), jObj.getDouble("score")); recognitions.add(result); } } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "cursor2visitwifi : EXTRA2 (recog results) json error."); } LociVisitWifi visit = new LociVisitWifi(visitId, placeId, enter, exit, recognitions, wifi); visits.add(visit); } while (cursor.moveToNext()); } cursor.close(); return visits; }