List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult deleteSMS(JSONObject filter, CallbackContext callbackContext) { Log.d(LOGTAG, ACTION_DELETE_SMS);//from ww w.j ava 2 s. c o m String uri_filter = filter.has(BOX) ? filter.optString(BOX) : "inbox"; int fread = filter.has(READ) ? filter.optInt(READ) : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString(ADDRESS); String fcontent = filter.optString(BODY); Activity ctx = this.cordova.getActivity(); int n = 0; try { Uri uri = Uri.parse((SMS_URI_ALL + uri_filter)); Cursor cur = ctx.getContentResolver().query(uri, (String[]) null, "", (String[]) null, null); while (cur.moveToNext()) { int id = cur.getInt(cur.getColumnIndex("_id")); boolean matchId = fid > -1 && fid == id; int read = cur.getInt(cur.getColumnIndex(READ)); boolean matchRead = fread > -1 && fread == read; String address = cur.getString(cur.getColumnIndex(ADDRESS)).trim(); boolean matchAddr = faddress.length() > 0 && address.equals(faddress); String body = cur.getString(cur.getColumnIndex(BODY)).trim(); boolean matchContent = fcontent.length() > 0 && body.equals(fcontent); if (!matchId && !matchRead && !matchAddr && !matchContent) continue; ctx.getContentResolver().delete(uri, "_id=" + id, (String[]) null); ++n; } callbackContext.success(n); } catch (Exception e) { callbackContext.error(e.toString()); } return null; }
From source file:com.textuality.lifesaver.Columns.java
public JSONObject cursorToJSON(Cursor cursor) { setColumns(cursor);/* www. j ava2s . c om*/ JSONObject json = new JSONObject(); try { for (int i = 0; i < names.length; i++) { int col = columns[i]; if (cursor.isNull(col)) continue; switch (types[i]) { case STRING: json.put(names[i], cursor.getString(col)); break; case INT: json.put(names[i], cursor.getInt(col)); break; case LONG: json.put(names[i], cursor.getLong(col)); break; case FLOAT: json.put(names[i], cursor.getFloat(col)); break; case DOUBLE: json.put(names[i], cursor.getDouble(col)); break; } } } catch (JSONException e) { throw new RuntimeException(e); } return json; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static U1Node getNodeByKey(String key) { String[] selectionArgs = new String[] { key }; String selection = Nodes.NODE_KEY + "=?"; String[] projection = Nodes.getDefaultProjection(); final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); if (c != null) { try {/*from w ww .j a va 2s .c o m*/ if (c.moveToFirst()) { String resourcePath; U1NodeKind kind; Boolean isLive = true; String path; String parentPath; String volumePath; Date whenCreated; Date whenChanged; Long generation; Long generationCreated; String contentPath; resourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); kind = U1NodeKind .valueOf(c.getString(c.getColumnIndex(Nodes.NODE_KIND)).toUpperCase(Locale.US)); isLive = c.getInt(c.getColumnIndex(Nodes.NODE_IS_LIVE)) != 0; path = c.getString(c.getColumnIndex(Nodes.NODE_PATH)); parentPath = c.getString(c.getColumnIndex(Nodes.NODE_PARENT_PATH)); volumePath = c.getString(c.getColumnIndex(Nodes.NODE_VOLUME_PATH)); whenCreated = new Date(c.getLong(c.getColumnIndex(Nodes.NODE_WHEN_CREATED))); whenChanged = new Date(c.getLong(c.getColumnIndex(Nodes.NODE_WHEN_CHANGED))); generation = c.getLong(c.getColumnIndex(Nodes.NODE_GENERATION)); generationCreated = c.getLong(c.getColumnIndex(Nodes.NODE_GENERATION_CREATED)); contentPath = c.getString(c.getColumnIndex(Nodes.NODE_CONTENT_PATH)); return new U1Node(resourcePath, kind, isLive, path, parentPath, volumePath, key, whenCreated, whenChanged, generation, generationCreated, contentPath); } else { return null; } } finally { c.close(); } } return null; }
From source file:org.noorganization.instalistsynch.controller.synch.impl.UnitSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000")); Cursor changeLog = mLocalLogController.getLogsSince(lastIndexTime, eModelType.UNIT); while (changeLog.moveToNext()) { int actionId = changeLog.getInt(changeLog.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); String uuid = changeLog.getString(changeLog.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); if (uuid.contentEquals("-")) continue; List<ModelMapping> existingMappings = mMappingController.get( ModelMapping.COLUMN.CLIENT_SIDE_UUID + " = ? AND " + ModelMapping.COLUMN.GROUP_ID + " = ?", new String[] { uuid, String.valueOf(_groupId) }); ModelMapping existingMapping = (existingMappings.size() == 0 ? null : existingMappings.get(0)); if (actionType == null) { Log.w(TAG, "Changelog contains entry without action."); continue; }//from w w w . ja v a 2 s .c o m switch (actionType) { case INSERT: { if (existingMapping == null) { ModelMapping newMapping = new ModelMapping(null, _groupId, null, uuid, new Date(Constants.INITIAL_DATE), new Date(), false); mMappingController.insert(newMapping); } break; } case UPDATE: { if (existingMapping == null) { Log.e(TAG, "Changelog contains update, but mapping does not exist. " + "Ignoring."); continue; } try { Date clientDate = ISO8601Utils.parse( changeLog.getString(changeLog.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); existingMapping.setLastClientChange(clientDate); mMappingController.update(existingMapping); } catch (ParseException e) { Log.e(TAG, "Change log contains invalid date: " + e.getMessage()); continue; } break; } case DELETE: { if (existingMapping == null) { Log.e(TAG, "Changelog contains deletion, but mapping does not exist. " + "Ignoring."); continue; } try { Date clientDate = ISO8601Utils.parse( changeLog.getString(changeLog.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); existingMapping.setLastClientChange(clientDate); existingMapping.setDeleted(true); mMappingController.update(existingMapping); } catch (ParseException e) { Log.e(TAG, "Change log contains invalid date: " + e.getMessage()); continue; } break; } } } changeLog.close(); }
From source file:com.digipom.manteresting.android.fragment.NailFragment.java
private boolean handleMenuItemSelected(int listItemPosition, int itemId) { listItemPosition -= listView.getHeaderViewsCount(); if (listItemPosition >= 0 && listItemPosition < nailAdapter.getCount()) { switch (itemId) { case R.id.share: try { final Cursor cursor = (Cursor) nailAdapter.getItem(listItemPosition); if (cursor != null && !cursor.isClosed()) { final int nailId = cursor.getInt(cursor.getColumnIndex(Nails.NAIL_ID)); final JSONObject nailJson = new JSONObject( cursor.getString(cursor.getColumnIndex(Nails.NAIL_JSON))); final Uri uri = MANTERESTING_SERVER.buildUpon().appendPath("nail") .appendPath(String.valueOf(nailId)).build(); String description = nailJson.getString("description"); if (description.length() > 100) { description = description.substring(0, 97) + ''; }// w ww . j a v a2 s . c om final String user = nailJson.getJSONObject("user").getString("username"); final String category = nailJson.getJSONObject("workbench").getJSONObject("category") .getString("title"); final Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, description + ' ' + uri.toString()); shareIntent.putExtra(Intent.EXTRA_SUBJECT, String.format(getResources().getString(R.string.shareSubject), user, category)); try { startActivity(Intent.createChooser(shareIntent, getText(R.string.share))); } catch (ActivityNotFoundException e) { new AlertDialog.Builder(getActivity()).setMessage(R.string.noShareApp).show(); } } } catch (Exception e) { if (LoggerConfig.canLog(Log.WARN)) { Log.w(TAG, "Could not share nail at position " + listItemPosition + " with id " + itemId); } } return true; default: return false; } } else { return false; } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
/** * Check the ferries terminal space sailing table for any starred entries. * If we find some, save them to a list so we can re-star those after we * flush the database./*from w w w . j a v a2 s . c o m*/ */ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(FerriesTerminalSailingSpace.CONTENT_URI, new String[] { FerriesTerminalSailingSpace.TERMINAL_ID }, FerriesTerminalSailingSpace.TERMINAL_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:io.github.protino.codewatch.ui.ProfileActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null) { if (data.moveToFirst()) { profileItem.setName(//w ww . j a va 2 s . c o m data.getString(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_DISPLAY_NAME))); profileItem.setDailyAverage( data.getInt(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_DAILY_AVERAGE))); profileItem.setLocation( data.getString(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_LOCATION))); profileItem .setWebsite(data.getString(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_WEBSITE))); profileItem.setEmail(data.getString(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_EMAIL))); profileItem.setLanguageStats( data.getString(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_LANGUAGE_STATS))); profileItem .setPhotoUrl(data.getString(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_PHOTO))); profileItem.setRank(data.getInt(data.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_RANK))); bindViews(); } } }
From source file:com.murrayc.galaxyzoo.app.syncadapter.SyncAdapter.java
private int getUploadedCount() { final ContentResolver resolver = getContentResolver(); final Cursor c = resolver.query(Item.ITEMS_URI, PROJECTION_COUNT_AS_COUNT, WHERE_CLAUSE_UPLOADED, new String[] {}, null); c.moveToFirst();//from w w w. j ava 2 s. co m final int result = c.getInt(0); c.close(); return result; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
/** * //w w w .j av a 2s . co m * * @return */ public static int qureyAllSessionUnreadCount() { int count = 0; String[] columnsList = { "sum(" + IThreadColumn.UNREAD_COUNT + ")" }; Cursor cursor = null; try { cursor = getInstance().sqliteDB().query(DatabaseHelper.TABLES_NAME_IM_SESSION, columnsList, null, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { count = cursor.getInt(cursor.getColumnIndex("sum(" + IThreadColumn.UNREAD_COUNT + ")")); } } } catch (Exception e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); } } return count; }
From source file:com.prey.json.actions.ContactsBackup.java
@TargetApi(Build.VERSION_CODES.ECLAIR) public HashMap<String, String> contacts2(Context ctx) { HashMap<String, String> parametersMap = new HashMap<String, String>(); String phoneNumber = null;/* ww w. java2 s . co m*/ int phoneType; String email = null; int emailType; Uri CONTENT_URI = ContactsContract.Contacts.CONTENT_URI; String _ID = ContactsContract.Contacts._ID; String DISPLAY_NAME = ContactsContract.Contacts.DISPLAY_NAME; String HAS_PHONE_NUMBER = ContactsContract.Contacts.HAS_PHONE_NUMBER; Uri PhoneCONTENT_URI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; String Phone_CONTACT_ID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID; String NUMBER = ContactsContract.CommonDataKinds.Phone.NUMBER; String NUMBER_TYPE = ContactsContract.CommonDataKinds.Phone.TYPE; Uri EmailCONTENT_URI = ContactsContract.CommonDataKinds.Email.CONTENT_URI; String EmailCONTACT_ID = ContactsContract.CommonDataKinds.Email.CONTACT_ID; String DATA = ContactsContract.CommonDataKinds.Email.DATA; String DATATYPE = ContactsContract.CommonDataKinds.Email.TYPE; Cursor cursor = ctx.getContentResolver().query(CONTENT_URI, null, null, null, null); // Loop for every contact in the phone if (cursor.getCount() > 0) { int i = 0; while (cursor.moveToNext()) { String contact_id = cursor.getString(cursor.getColumnIndex(_ID)); String name = cursor.getString(cursor.getColumnIndex(DISPLAY_NAME)); int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER))); if (hasPhoneNumber > 0) { PreyLogger.i("____________"); parametersMap.put("contacts_backup[" + i + "][display_name]", name); parametersMap.put("contacts_backup[" + i + "][nickname][name]", name); parametersMap.put("contacts_backup[" + i + "][nickname][label]", name); PreyLogger.i("contacts_backup[" + i + "][display_name]" + name); PreyLogger.i("contacts_backup[" + i + "][nickname][name]" + name); PreyLogger.i("contacts_backup[" + i + "][nickname][label]" + name); // Query and loop for every phone number of the contact Cursor phoneCursor = ctx.getContentResolver().query(PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?", new String[] { contact_id }, null); int j = 0; while (phoneCursor.moveToNext()) { phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER)); phoneType = phoneCursor.getInt(phoneCursor.getColumnIndex(NUMBER_TYPE)); parametersMap.put("contacts_backup[" + i + "][phones][" + j + "][number]", phoneNumber); parametersMap.put("contacts_backup[" + i + "][phones][" + j + "][type]", typePhone(phoneType)); PreyLogger.i("contacts_backup[" + i + "][phones][" + j + "][number]" + phoneNumber); PreyLogger.i("contacts_backup[" + i + "][phones][" + j + "][type]" + typePhone(phoneType)); j++; } // while phone phoneCursor.close(); // Query and loop for every email of the contact Cursor emailCursor = ctx.getContentResolver().query(EmailCONTENT_URI, null, EmailCONTACT_ID + " = ?", new String[] { contact_id }, null); j = 0; while (emailCursor.moveToNext()) { email = emailCursor.getString(emailCursor.getColumnIndex(DATA)); emailType = emailCursor.getInt(emailCursor.getColumnIndex(DATATYPE)); parametersMap.put("contacts_backup[" + i + "][emails][" + j + "][address]", email); parametersMap.put("contacts_backup[" + i + "][emails][" + j + "][type]", typeMail(emailType)); PreyLogger.i("contacts_backup[" + i + "][emails][" + j + "][address]" + email); PreyLogger.i("contacts_backup[" + i + "][emails][" + j + "][type]" + typeMail(emailType)); j++; } // while email emailCursor.close(); i = i + 1; } // if hasPhoneNumber } // while cursor // } // if cursor return parametersMap; }