List of usage examples for android.database Cursor getCount
int getCount();
From source file:com.mpower.mintel.android.tasks.DownloadFormsTask.java
@Override protected HashMap<String, String> doInBackground(ArrayList<FormDetails>... values) { ArrayList<FormDetails> toDownload = values[0]; int total = toDownload.size(); int count = 1; HashMap<String, String> result = new HashMap<String, String>(); for (int i = 0; i < total; i++) { FormDetails fd = toDownload.get(i); publishProgress(fd.formName, Integer.valueOf(count).toString(), Integer.valueOf(total).toString()); String message = ""; try {/*from w w w . j a v a 2s .c o m*/ // get the xml file // if we've downloaded a duplicate, this gives us the file File dl = downloadXform(fd.formName, fd.downloadUrl); String[] projection = { FormsColumns._ID, FormsColumns.FORM_FILE_PATH }; String[] selectionArgs = { dl.getAbsolutePath() }; String selection = FormsColumns.FORM_FILE_PATH + "=?"; Cursor alreadyExists = MIntel.getInstance().getContentResolver().query(FormsColumns.CONTENT_URI, projection, selection, selectionArgs, null); Uri uri = null; if (alreadyExists.getCount() <= 0) { // doesn't exist, so insert it ContentValues v = new ContentValues(); v.put(FormsColumns.FORM_FILE_PATH, dl.getAbsolutePath()); HashMap<String, String> formInfo = FileUtils.parseXML(dl); v.put(FormsColumns.DISPLAY_NAME, formInfo.get(FileUtils.TITLE)); v.put(FormsColumns.MODEL_VERSION, formInfo.get(FileUtils.MODEL)); v.put(FormsColumns.UI_VERSION, formInfo.get(FileUtils.UI)); v.put(FormsColumns.JR_FORM_ID, formInfo.get(FileUtils.FORMID)); v.put(FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI)); uri = MIntel.getInstance().getContentResolver().insert(FormsColumns.CONTENT_URI, v); } else { alreadyExists.moveToFirst(); uri = Uri.withAppendedPath(FormsColumns.CONTENT_URI, alreadyExists.getString(alreadyExists.getColumnIndex(FormsColumns._ID))); } if (fd.manifestUrl != null) { Cursor c = MIntel.getInstance().getContentResolver().query(uri, null, null, null, null); if (c.getCount() > 0) { // should be exactly 1 c.moveToFirst(); String error = downloadManifestAndMediaFiles( c.getString(c.getColumnIndex(FormsColumns.FORM_MEDIA_PATH)), fd, count, total); if (error != null) { message += error; } } } else { // TODO: manifest was null? Log.e(t, "Manifest was null. PANIC"); } } catch (SocketTimeoutException se) { se.printStackTrace(); message += se.getMessage(); } catch (Exception e) { e.printStackTrace(); if (e.getCause() != null) { message += e.getCause().getMessage(); } else { message += e.getMessage(); } } count++; if (message.equalsIgnoreCase("")) { message = MIntel.getInstance().getString(R.string.success); } result.put(fd.formName, message); } return result; }
From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java
public static String queryBodyBymsgId(String contactId) { Cursor cursor = null; String threadId = null;/*from w w w .j a va2s .co m*/ if (contactId != null) { String where = IMessageColumn.MESSAGE_ID + " = '" + contactId + "' "; try { cursor = getInstance().sqliteDB().query(DatabaseHelper.TABLES_NAME_IM_MESSAGE, null, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { threadId = cursor.getString(cursor.getColumnIndexOrThrow(IMessageColumn.BODY)); } } } catch (SQLException e) { LogUtil.e(TAG + " " + e.toString()); } finally { if (cursor != null) { cursor.close(); cursor = null; } } } return threadId; }
From source file:com.mpower.daktar.android.tasks.DownloadFormsTask.java
@Override protected HashMap<String, String> doInBackground(final ArrayList<FormDetails>... values) { final ArrayList<FormDetails> toDownload = values[0]; final int total = toDownload.size(); int count = 1; final HashMap<String, String> result = new HashMap<String, String>(); for (int i = 0; i < total; i++) { final FormDetails fd = toDownload.get(i); publishProgress(fd.formName, Integer.valueOf(count).toString(), Integer.valueOf(total).toString()); String message = ""; try {// w ww. j av a 2s .c om // get the xml file // if we've downloaded a duplicate, this gives us the file final File dl = downloadXform(fd.formName, fd.downloadUrl); final String[] projection = { BaseColumns._ID, FormsColumns.FORM_FILE_PATH }; final String[] selectionArgs = { dl.getAbsolutePath() }; final String selection = FormsColumns.FORM_FILE_PATH + "=?"; final Cursor alreadyExists = MIntel.getInstance().getContentResolver() .query(FormsColumns.CONTENT_URI, projection, selection, selectionArgs, null); Uri uri = null; if (alreadyExists.getCount() <= 0) { // doesn't exist, so insert it final ContentValues v = new ContentValues(); v.put(FormsColumns.FORM_FILE_PATH, dl.getAbsolutePath()); final HashMap<String, String> formInfo = FileUtils.parseXML(dl); v.put(FormsColumns.DISPLAY_NAME, formInfo.get(FileUtils.TITLE)); v.put(FormsColumns.MODEL_VERSION, formInfo.get(FileUtils.MODEL)); v.put(FormsColumns.UI_VERSION, formInfo.get(FileUtils.UI)); v.put(FormsColumns.JR_FORM_ID, formInfo.get(FileUtils.FORMID)); v.put(FormsColumns.SUBMISSION_URI, formInfo.get(FileUtils.SUBMISSIONURI)); uri = MIntel.getInstance().getContentResolver().insert(FormsColumns.CONTENT_URI, v); } else { alreadyExists.moveToFirst(); uri = Uri.withAppendedPath(FormsColumns.CONTENT_URI, alreadyExists.getString(alreadyExists.getColumnIndex(BaseColumns._ID))); } if (fd.manifestUrl != null) { final Cursor c = MIntel.getInstance().getContentResolver().query(uri, null, null, null, null); if (c.getCount() > 0) { // should be exactly 1 c.moveToFirst(); final String error = downloadManifestAndMediaFiles( c.getString(c.getColumnIndex(FormsColumns.FORM_MEDIA_PATH)), fd, count, total); if (error != null) { message += error; } } } else { // TODO: manifest was null? Log.e(t, "Manifest was null. PANIC"); } } catch (final SocketTimeoutException se) { se.printStackTrace(); message += se.getMessage(); } catch (final Exception e) { e.printStackTrace(); if (e.getCause() != null) { message += e.getCause().getMessage(); } else { message += e.getMessage(); } } count++; if (message.equalsIgnoreCase("")) { message = MIntel.getInstance().getString(R.string.success); } result.put(fd.formName, message); } return result; }
From source file:fi.hut.soberit.sensors.services.BatchDataUploadService.java
protected void writeSessionHeader(final FileWriter destination, final Session session, Cursor rowCursor) throws IOException { destination.write(String.format("{\"session\": {\"id\": \"%d\", \"start\": \"%s\", \"end\": \"%s\"}, ", session.getId(), DatabaseHelper.getUtcDateString(session.getStart()), DatabaseHelper.getUtcDateString(session.getEnd()))); if (rowCursor.getCount() != 0) { destination.write(" \"values\": ["); }//from w ww . j a va2s.c o m }
From source file:org.noorganization.instalistsynch.controller.synch.impl.IngredientSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000"); boolean isLocal = false; GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup(); if (groupAuth != null) { isLocal = groupAuth.getGroupId() == _groupId; }/*from ww w .ja va 2 s . c o m*/ Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType); if (logCursor.getCount() == 0) { logCursor.close(); return; } try { while (logCursor.moveToNext()) { // fetch the action type int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); List<ModelMapping> modelMappingList = mIngredientModelMapping.get( ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID + " LIKE ?", new String[] { String.valueOf(_groupId), logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) }); ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0); switch (actionType) { case INSERT: // skip insertion because this should be decided by the user if the non local groups should have access to the category // and also skip if a mapping for this case already exists! if (!isLocal || modelMapping != null) { continue; } String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); Date clientDate = ISO8601Utils.parse( logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid, new Date(Constants.INITIAL_DATE), clientDate, false); mIngredientModelMapping.insert(modelMapping); break; case UPDATE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mIngredientModelMapping.update(modelMapping); break; case DELETE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } modelMapping.setDeleted(true); timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mIngredientModelMapping.update(modelMapping); break; default: } } } catch (Exception e) { logCursor.close(); } }
From source file:com.gvccracing.android.tttimer.Tabs.RaceInfoTab.java
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { try {/*from w w w . ja va 2 s .c o m*/ Log.i(LOG_TAG(), "onLoadFinished start: id=" + Integer.toString(loader.getId())); switch (loader.getId()) { case RACE_INFO_LOADER: cursor.moveToFirst(); if (cursor.getCount() > 0) { Long raceDateMS = cursor.getLong(cursor.getColumnIndex(Race.RaceDate)); String courseName = cursor.getString(cursor.getColumnIndex(RaceLocation.CourseName)); long raceTypeID = cursor.getLong(cursor.getColumnIndex(Race.RaceType)); String raceTypeName = RaceType.DescriptionFromRaceTypeID(raceTypeID); String startIntervalText = Long .toString(cursor.getLong(cursor.getColumnIndex(Race.StartInterval))); long numRaceLaps = cursor.getLong(cursor.getColumnIndex(Race.NumLaps)); distance = Float.toString( cursor.getFloat(cursor.getColumnIndex(RaceLocation.Distance)) * (float) numRaceLaps); if (distance == null) { distance = ""; } if (raceTypeID == 1) { raceLaps.setText(Long.toString(numRaceLaps)); llRaceLaps.setVisibility(View.VISIBLE); } else { llRaceLaps.setVisibility(View.GONE); } Date raceDateTemp = new Date(raceDateMS); SimpleDateFormat formatter = new SimpleDateFormat("M/d/yy"); raceDate.setText(formatter.format(raceDateTemp).toString()); raceCourseName.setText(courseName); raceType.setText(raceTypeName); raceStartInterval.setText(startIntervalText); SetDistance(); } break; case APP_SETTINGS_LOADER_RACEINFO: getActivity().getSupportLoaderManager().restartLoader(COURSE_RECORD_LOADER, null, this); Integer distanceUnitID = Integer.parseInt(AppSettings.Instance().ReadValue(getActivity(), AppSettings.AppSetting_DistanceUnits_Name, "0")); distanceUnit = "mi"; switch (distanceUnitID) { case 0: distanceUnit = "mi"; break; case 1: distanceUnit = "km"; break; default: distanceUnit = "mi"; break; } getActivity().getSupportLoaderManager().restartLoader(RACE_INFO_LOADER, null, this); break; case COURSE_RECORD_LOADER: if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); long elapsedTime = cursor.getLong(cursor.getColumnIndex(RaceResults.ElapsedTime)); if (courseRecord != null) { courseRecord.setText(TimeFormatter.Format(elapsedTime, true, true, true, true, true, false, false, false)); } } break; } Log.i(LOG_TAG(), "onLoadFinished complete: id=" + Integer.toString(loader.getId())); } catch (Exception ex) { Log.e(LOG_TAG(), "onLoadFinished error", ex); } }
From source file:com.android.contacts.list.ContactEntryListAdapter.java
/** * Updates partitions according to the directory meta-data contained in the supplied * cursor./*from www .java 2s .c om*/ */ public void changeDirectories(Cursor cursor) { if (cursor.getCount() == 0) { // Directory table must have at least local directory, without which this adapter will // enter very weird state. Log.e(TAG, "Directory search loader returned an empty cursor, which implies we have " + "no directory entries.", new RuntimeException()); return; } HashSet<Long> directoryIds = new HashSet<Long>(); int idColumnIndex = cursor.getColumnIndex(Directory._ID); int directoryTypeColumnIndex = cursor.getColumnIndex(DirectoryListLoader.DIRECTORY_TYPE); int displayNameColumnIndex = cursor.getColumnIndex(Directory.DISPLAY_NAME); int photoSupportColumnIndex = cursor.getColumnIndex(Directory.PHOTO_SUPPORT); // TODO preserve the order of partition to match those of the cursor // Phase I: add new directories cursor.moveToPosition(-1); while (cursor.moveToNext()) { long id = cursor.getLong(idColumnIndex); directoryIds.add(id); if (getPartitionByDirectoryId(id) == -1) { DirectoryPartition partition = new DirectoryPartition(false, true); partition.setDirectoryId(id); partition.setDirectoryType(cursor.getString(directoryTypeColumnIndex)); partition.setDisplayName(cursor.getString(displayNameColumnIndex)); int photoSupport = cursor.getInt(photoSupportColumnIndex); partition.setPhotoSupported(photoSupport == Directory.PHOTO_SUPPORT_THUMBNAIL_ONLY || photoSupport == Directory.PHOTO_SUPPORT_FULL); addPartition(partition); } } // Phase II: remove deleted directories int count = getPartitionCount(); for (int i = count; --i >= 0;) { Partition partition = getPartition(i); if (partition instanceof DirectoryPartition) { long id = ((DirectoryPartition) partition).getDirectoryId(); if (!directoryIds.contains(id)) { removePartition(i); } } } invalidate(); notifyDataSetChanged(); }
From source file:net.gaast.giggity.Db.java
private void updateSchedule(SQLiteDatabase db, Seed.Schedule sched, int last_version) { if (sched.start.equals(sched.end)) { /* If it's one day only, avoid having start == end. Pretend it's from 6:00 'til 18:00 or something. */ sched.start.setHours(6);//w ww. j a v a 2 s. c om sched.end.setHours(18); } else { /* For different days, pretend the even't from noon to noon. In both cases, we'll have exact times * once we load the schedule for the first time. */ sched.start.setHours(12); sched.end.setHours(12); } Cursor q = db.rawQuery("Select sch_id From schedule Where sch_url = ?", new String[] { sched.url }); Log.d("cursor", "" + q.getCount()); if (sched.version > last_version && q.getCount() == 0) { ContentValues row = new ContentValues(); if (sched.id != null) row.put("sch_id_s", sched.id); else row.put("sch_id_s", Schedule.hashify(sched.url)); row.put("sch_url", sched.url); row.put("sch_title", sched.title); row.put("sch_atime", sched.start.getTime() / 1000); row.put("sch_start", sched.start.getTime() / 1000); row.put("sch_end", sched.end.getTime() / 1000); row.put("sch_metadata", sched.metadata); db.insert("schedule", null, row); } else if (q.getCount() == 1) { q.moveToNext(); if (oldDbVer < 8) { /* We're upgrading from < 8 so we have to backfill the start/end columns. */ ContentValues row = new ContentValues(); row.put("sch_start", sched.start.getTime() / 1000); row.put("sch_end", sched.end.getTime() / 1000); db.update("schedule", row, "sch_id = ?", new String[] { q.getString(0) }); } /* Always refresh the metadata, seedfile is authoritative. */ if (sched.metadata != "") { ContentValues row = new ContentValues(); row.put("sch_metadata", sched.metadata); db.update("schedule", row, "sch_id = ?", new String[] { q.getString(0) }); } } q.close(); }
From source file:cn.code.notes.gtask.data.SqlNote.java
private void loadDataContent() { Cursor c = null; mDataList.clear();//w ww .ja v a 2 s . com try { c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, "(note_id=?)", new String[] { String.valueOf(mId) }, null); if (c != null) { if (c.getCount() == 0) { Log.w(TAG, "it seems that the note has not data"); return; } while (c.moveToNext()) { SqlData data = new SqlData(mContext, c); mDataList.add(data); } } else { Log.w(TAG, "loadDataContent: cursor = null"); } } finally { if (c != null) c.close(); } }
From source file:com.polyvi.xface.extension.camera.XCameraExt.java
public void takePicture(int mEncodingType) { Cursor cursor = queryImgDB(); if (null != cursor) { mNumPics = cursor.getCount();// ?? } else {/*from w w w .j a v a2 s. c o m*/ mNumPics = 0;//Cursor } // ?camera? Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); File photo = createCaptureFile(mEncodingType); // // ?URI??? intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo)); mImageUri = Uri.fromFile(photo); // ?Camera??onActivityResult? mExtensionContext.getSystemContext().startActivityForResult(this, intent, CAMERA_REQUEST_CODE); }