Java Code Examples for android.database.Cursor#getCount()
The following examples show how to use
android.database.Cursor#getCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoldProductInfo.java From Android-POS with MIT License | 6 votes |
public ArrayList<SoldProductModel> getAllSoldProductInfo(){ this.Open(); ArrayList<SoldProductModel> allSoldProduct = new ArrayList<>(); Cursor cursor = database.query(dbHelper.TABLE_SOLD_PRODUCT_NAME, null, null, null, null, null, null); cursor.moveToFirst(); int temp = cursor.getCount(); for (int i = 0; i<temp; i++){ SoldProductModel soldProduct = new SoldProductModel(cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_CODE)), cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_SELL_ID)), cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_PRODUCT_ID)), cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_PRICE)), cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_QUANTITY)), cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_TOTAL_PRICE)), cursor.getString(cursor.getColumnIndex(dbHelper.COL_SOLD_PRODUCT_PENDING_STATUS)) ); allSoldProduct.add(soldProduct); cursor.moveToNext(); } this.Close(); if (temp > 0 )return allSoldProduct; else return null; }
Example 2
Source File: DatabaseBackend.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
public ServiceDiscoveryResult findDiscoveryResult(final String hash, final String ver) { SQLiteDatabase db = this.getReadableDatabase(); String[] selectionArgs = {hash, ver}; Cursor cursor = db.query(ServiceDiscoveryResult.TABLENAME, null, ServiceDiscoveryResult.HASH + "=? AND " + ServiceDiscoveryResult.VER + "=?", selectionArgs, null, null, null); if (cursor.getCount() == 0) { cursor.close(); return null; } cursor.moveToFirst(); ServiceDiscoveryResult result = null; try { result = new ServiceDiscoveryResult(cursor); } catch (JSONException e) { /* result is still null */ } cursor.close(); return result; }
Example 3
Source File: RemindersDao.java From narrate-android with Apache License 2.0 | 6 votes |
public static Reminder getReminder(String uuid) { SQLiteDatabase db = DatabaseHelper.getInstance(GlobalApplication.getAppContext()).getReadableDatabase(); Reminder reminder = null; Cursor cursor = null; try { cursor = db.query(REMINDERS, null, UUID + "=?", new String[] { uuid }, null, null, null); if ((cursor != null) && (cursor.getCount() > 0)) { cursor.moveToFirst(); reminder = fromCursor(cursor); } } finally { if ( cursor != null ) cursor.close(); } return reminder; }
Example 4
Source File: SearchDB.java From moviedb-android with Apache License 2.0 | 6 votes |
public int getSuggestionSize() { SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); queryBuilder.setProjectionMap(mAliasMap); queryBuilder.setTables(TABLE2_NAME); Cursor c = queryBuilder.query(mSearchDBOpenHelper.getReadableDatabase(), new String[]{"_ID", SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA}, null, null, null, null, null, "10" ); return c.getCount(); }
Example 5
Source File: MainActivity.java From recent-images with MIT License | 6 votes |
private int getOrientation(ContentResolver cr, int id) { String photoID = String.valueOf(id); Cursor cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[]{MediaStore.Images.Media.ORIENTATION}, MediaStore.Images.Media._ID + "=?", new String[]{"" + photoID}, null); int orientation = -1; if (cursor.getCount() != 1) { return -1; } if (cursor.moveToFirst()) { orientation = cursor.getInt(0); } cursor.close(); return orientation; }
Example 6
Source File: ThumbnailsDatabase.java From iZhihu with GNU General Public License v2.0 | 6 votes |
public List<String> getNotCachedThumbnails() { SQLiteDatabase db = new DatabaseOpenHelper(context).getReadableDatabase(); Cursor cursor = db.query(DATABASE_THUMBNAILS_TABLE_NAME, new String[]{COLUM_URL}, COLUM_LOCAL_PATH + " IS NULL AND " + COLUM_STATUS + " IS NULL", null, null, null, COLUM_ID + " DESC", null); int idxUrl = cursor.getColumnIndex(COLUM_URL); List<String> result = new ArrayList<String>(); try { for (int i = 0, count = cursor.getCount(); i < count; i++) { cursor.moveToPosition(i); result.add(cursor.getString(idxUrl)); } return result; } finally { cursor.close(); db.close(); } }
Example 7
Source File: MergeCursor.java From libcommon with Apache License 2.0 | 5 votes |
@Override public boolean onMove(int oldPosition, int newPosition) { synchronized (mCursors) { /* Find the right cursor */ mCursor = null; mIndex = -1; int cursorStartPos = 0; int index = -1; for (final Cursor cursor: mCursors) { index++; if (cursor == null) { continue; } if (newPosition < (cursorStartPos + cursor.getCount())) { mCursor = cursor; mIndex = index; break; } cursorStartPos += cursor.getCount(); } /* Move it to the right position */ if (mCursor != null) { boolean ret = mCursor.moveToPosition(newPosition - cursorStartPos); return ret; } } return false; }
Example 8
Source File: ConversationView.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
@Override public void onImageClicked(MessageViewHolder viewHolder, Uri image) { Cursor c = getCursor(); if (c != null && c.moveToFirst()) { ArrayList<Uri> urisToShow = new ArrayList<>(c.getCount()); ArrayList<String> mimeTypesToShow = new ArrayList<>(c.getCount()); ArrayList<String> messagePacketIds = new ArrayList<>(c.getCount()); do { try { String mime = c.getString(mMimeTypeColumn); if (!TextUtils.isEmpty(mime) && mime.startsWith("image")) { Uri uri = Uri.parse(c.getString(mBodyColumn)); urisToShow.add(uri); mimeTypesToShow.add(mime); messagePacketIds.add(c.getString(mPacketIdColumn)); } } catch (Exception ignored) { } } while (c.moveToNext()); Intent intent = new Intent(mContext, ImageViewActivity.class); intent.putExtra("showResend",true); // These two are parallel arrays intent.putExtra(ImageViewActivity.URIS, urisToShow); intent.putExtra(ImageViewActivity.MIME_TYPES, mimeTypesToShow); intent.putExtra(ImageViewActivity.MESSAGE_IDS, messagePacketIds); int indexOfCurrent = urisToShow.indexOf(image); if (indexOfCurrent == -1) { indexOfCurrent = 0; } intent.putExtra(ImageViewActivity.CURRENT_INDEX, indexOfCurrent); mContext.startActivityForResult(intent,ConversationDetailActivity.REQUEST_IMAGE_VIEW); } }
Example 9
Source File: Database.java From wallpaperboard with Apache License 2.0 | 5 votes |
public int getCategoryCount(String category) { if (!openDatabase()) { LogUtil.e("Database error: getCategoryCount() failed to open database"); return 0; } Cursor cursor = mDatabase.get().mSQLiteDatabase.query(TABLE_WALLPAPERS, null, "LOWER(" +KEY_CATEGORY+ ") LIKE ?", new String[]{"%" +category.toLowerCase(Locale.getDefault())+ "%"}, null, null, null); int count = cursor.getCount(); cursor.close(); return count; }
Example 10
Source File: Database.java From Pedometer with Apache License 2.0 | 5 votes |
/** * Get the number of steps taken between 'start' and 'end' date * <p/> * Note that todays entry might have a negative value, so take care of that * if 'end' >= Util.getToday()! * * @param start start date in ms since 1970 (steps for this date included) * @param end end date in ms since 1970 (steps for this date included) * @return the number of steps from 'start' to 'end'. Can be < 0 as todays * entry might have negative value */ public int getSteps(final long start, final long end) { Cursor c = getReadableDatabase() .query(DB_NAME, new String[]{"SUM(steps)"}, "date >= ? AND date <= ?", new String[]{String.valueOf(start), String.valueOf(end)}, null, null, null); int re; if (c.getCount() == 0) { re = 0; } else { c.moveToFirst(); re = c.getInt(0); } c.close(); return re; }
Example 11
Source File: OrmLiteCursorLoader.java From ormlite-android with ISC License | 5 votes |
@Override public Cursor loadInBackground() { Cursor cursor; try { DatabaseConnection connection = dao.getConnectionSource().getReadOnlyConnection(dao.getTableName()); AndroidCompiledStatement statement = (AndroidCompiledStatement) query.compile(connection, SELECT); cursor = statement.getCursor(); } catch (SQLException e) { throw new RuntimeException(e); } // fill the cursor with results cursor.getCount(); return cursor; }
Example 12
Source File: FeatureChanges.java From android_maplib with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean haveFeaturesNotSyncFlag(String tableName) { String selection = "( 0 != ( " + FIELD_OPERATION + " & " + CHANGE_OPERATION_NOT_SYNC + " ) )"; Cursor changesCursor = query(tableName, selection, null, "1"); boolean res = false; if (null != changesCursor) { res = changesCursor.getCount() > 0; changesCursor.close(); } return res; }
Example 13
Source File: ContactSqlHelper.java From Meshenger with GNU General Public License v3.0 | 5 votes |
public boolean contactSaved(String identifier){ Log.d("SQL", "searching " + identifier); Cursor c = database.query(this.tableName, new String[]{columnID}, columnIdentifier + "=?", new String[]{identifier}, null, null, null); boolean has = c.getCount() > 0; c.close(); return has; }
Example 14
Source File: PredatorDatabase.java From Capstone-Project with MIT License | 5 votes |
public List<InstallLink> getInstallLinksForPost(int postId) { Cursor installLinksCursor = mContentResolver.query(PredatorContract.InstallLinksEntry.CONTENT_URI_INSTALL_LINKS, null, PredatorContract.InstallLinksEntry.COLUMN_POST_ID + " = " + postId, null, null); List<InstallLink> installLinks = new ArrayList<>(); if (installLinksCursor != null && installLinksCursor.getCount() != 0) { installLinks = PredatorDbValuesHelper.getInstallLinksFromCursor(installLinksCursor); } closeCursor(installLinksCursor); return installLinks; }
Example 15
Source File: patientProvider.java From Doctorave with MIT License | 4 votes |
@Nullable @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { SQLiteDatabase db = mPatientHelper.getReadableDatabase(); int match = sUriMatcher.match(uri); Cursor cursor = null; switch (match){ case PATIENTS: cursor = db.query(patientEntry.tableName(doctorPreference.getUsernameFromSP(MyApplication.getAppContext())), projection, selection, selectionArgs, null, null, sortOrder); break; case PATIENT_ID: List list4 = uri.getPathSegments(); selection = patientEntry.COLUMN_PUSH_ID + "=?"; selectionArgs = new String[]{String.valueOf(list4.get(2))}; cursor = db.query(patientEntry.tableName(doctorPreference.getUsernameFromSP(MyApplication.getAppContext())), projection, selection, selectionArgs, null, null, sortOrder); break; case PATIENT_NAME: List list2 = uri.getPathSegments(); String name = (String) list2.get(1); selection = patientEntry.COLUMN_NAME + " LIKE ?"; selectionArgs = new String[]{"%" + name + "%"}; cursor = db.query(patientEntry.tableName(doctorPreference.getUsernameFromSP(MyApplication.getAppContext())), projection, selection, selectionArgs, null, null, sortOrder); break; case DOCTOR_ID: List list = uri.getPathSegments(); String username = (String) list.get(1); String password = (String) list.get(2); selection = doctorEntry.COLUMN_EMAIL + "=?"; selectionArgs = new String[]{username}; Cursor cursor1 = db.query(doctorEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); if(cursor1.getCount() == 0){ return cursor1; //Do Nothing }else { selection = doctorEntry.COLUMN_PASSWORD + "=?"; selectionArgs = new String[]{password}; cursor1.moveToFirst(); Cursor cursor2 = db.query(doctorEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); if(cursor2.getCount() == 0){ return cursor2; }else { cursor2.moveToFirst(); return cursor1; } } case SPECIFIC_DOCTOR: selection = doctorEntry.COLUMN_EMAIL + "=?"; List list1 = uri.getPathSegments(); String username1 = (String) list1.get(1); selection = doctorEntry.COLUMN_EMAIL + "=?"; selectionArgs = new String[]{username1}; cursor = db.query(doctorEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; default: throw new IllegalArgumentException(); } cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example 16
Source File: GoogleBackup.java From haxsync with GNU General Public License v2.0 | 4 votes |
protected Boolean doInBackground(Void... params){ AccountManager am = AccountManager.get(parent); Account account = am.getAccountsByType(parent.getString(R.string.ACCOUNT_TYPE))[0]; if (FacebookUtil.authorize(parent, account)){ String selfID = FacebookUtil.getSelfID(); if (selfID == null){ return false; } String googleName = googleAcc.name; Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type) .build(); Uri googleUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, googleName) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, "com.google") .build(); ContentResolver mContentResolver = parent.getContentResolver(); Cursor c1 = mContentResolver.query(rawContactUri, new String[] { BaseColumns._ID, RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY, RawContacts.SYNC1 }, null, null, null); while (c1.moveToNext()) { long contactID = c1.getLong(c1.getColumnIndex(RawContacts.CONTACT_ID)); Cursor c2 = mContentResolver.query(googleUri, new String[] { BaseColumns._ID}, RawContacts.CONTACT_ID +" = '" + contactID + "'", null, null); if (c2.getCount() > 0){ c2.moveToFirst(); contactName = c1.getString(c1.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY)); writeHTCData(c2.getLong(c2.getColumnIndex(BaseColumns._ID)), selfID, c1.getString(c1.getColumnIndex(RawContacts.SYNC1))); publishProgress((int) ((c1.getPosition() / (float) c1.getCount()) * 100)); } c2.close(); //Log.i("backup", ); } c1.close(); ContentResolver.requestSync(googleAcc, ContactsContract.AUTHORITY, new Bundle()); return true; } else{ return false; } }
Example 17
Source File: ImageSelectorFragment.java From Android-ImagesPickers with Apache License 2.0 | 4 votes |
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null) { int count = data.getCount(); if (count > 0) { List<Image> tempImageList = new ArrayList<Image>(); data.moveToFirst(); do { String path = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[0])); String name = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[1])); long dateTime = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[2])); Image image = new Image(path, name, dateTime); tempImageList.add(image); if (!hasFolderGened) { File imageFile = new File(path); File folderFile = imageFile.getParentFile(); Folder folder = new Folder(); folder.name = folderFile.getName(); folder.path = folderFile.getAbsolutePath(); folder.cover = image; if (!folderList.contains(folder)) { List<Image> imageList = new ArrayList<Image>(); imageList.add(image); folder.images = imageList; folderList.add(folder); } else { Folder f = folderList.get(folderList.indexOf(folder)); f.images.add(image); } } } while (data.moveToNext()); imageList.clear(); imageList.addAll(tempImageList); imageAdapter.notifyDataSetChanged(); if (resultList != null && resultList.size() > 0) { imageAdapter.setDefaultSelected(resultList); } folderAdapter.setData(folderList); hasFolderGened = true; } } }
Example 18
Source File: DataList.java From trekarta with GNU General Public License v3.0 | 4 votes |
@Override public void changeCursor(Cursor cursor) { super.changeCursor(cursor); mCellStates = cursor == null ? null : new int[cursor.getCount()]; }
Example 19
Source File: CalendarResolver.java From mCalendar with Apache License 2.0 | 4 votes |
public ArrayList<TaskBean> getEventsByMonth(int year, int month){ ArrayList<TaskBean> ret = new ArrayList<>(); Long start = Long.parseLong(TimeStampUtil.toUnixTimeStamp(new DateData(year, month, 1))); Calendar tmp = Calendar.getInstance(); tmp.set(year, month - 1, 1); tmp.set(year, month - 1, tmp.getMaximum(Calendar.DAY_OF_MONTH)); Long end = tmp.getTimeInMillis(); end += 86400000; Cursor cursor = contentResolver.query(EVENTS_URI, EVENTS_FIELDS, new StringBuilder().append(CalendarContract.Events.DTSTART).append(">=? AND ").append(CalendarContract.Events.DTEND).append("<?").append(" AND ( ").append(CalendarContract.Events.RRULE).append(" IS NULL OR ").append(CalendarContract.Events.RRULE).append(" ='' )").toString(), new String[]{start.toString(), end.toString()}, null); if (cursor.getCount() > 0){ while (cursor.moveToNext()){ ret.add(new TaskBean().populate(cursor)); } } cursor.close(); cursor = contentResolver.query(EVENTS_URI, EVENTS_FIELDS, CalendarContract.Events.RRULE + "!= ''", null, null); TaskBean toAdd; if (cursor.getCount() > 0){ while (cursor.moveToNext()){ toAdd = new TaskBean().populate(cursor); if (toAdd.getrRule() != null){ ret.addAll(RecurrenceUtil.getAllRecurrence( toAdd, TimeStampUtil.toDateData(start), TimeStampUtil.toDateData(end) )); } else { ret.add(toAdd); } } } cursor.close(); Collections.sort(ret); return ret; }
Example 20
Source File: DemoRecordSupport.java From android-auto-call-recorder with MIT License | 4 votes |
/** * create and insert db record using a real contact information. * * @param contactID - the target contact id. If id = -1 then get a random one */ public void createDemoRecord(long contactID) { Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; // TODO: 17.05.2017 @contact_ID String[] projection = { ContactsContract.PhoneLookup.CONTACT_ID, // ContactsContract.CommonDataKinds.Phone._ID, //the same as phonelookup_ID ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER }; String selection = contactID != 0 ? ContactsContract.PhoneLookup.CONTACT_ID + " = ?" : null; String[] selectionArguments = contactID != 0 ? new String[]{String.valueOf(contactID)} : null; String orderBy = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC"; AsyncQueryHandler asyncQueryHandler = new AsyncQueryHandler(mContext.getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { if (cursor.getCount() == 0) { // createDummyRecord(mContext); return; } mCursorLogger.log(cursor); if (cursor.getCount() == 1) { cursor.moveToFirst(); } else { int random = generateNumber(cursor.getCount() - 1, 0); cursor.moveToPosition(random); } Contact contact = new MicroOrm().fromCursor(cursor, Contact.class); // long contact_id = cursor.getLong(cursor.getColumnIndex(ContactsContract.PhoneLookup.CONTACT_ID)); // String contact_number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); ContentValues values = new ContentValues(); // values.put(RecordDbContract.RecordItem.COLUMN_ID, String.valueOf(generateNumber(10000, 5000))); values.put(RecordDbContract.RecordItem.COLUMN_PATH, mConstant.DEMO_PATH); values.put(RecordDbContract.RecordItem.COLUMN_DATE, generateDate()); values.put(RecordDbContract.RecordItem.COLUMN_NUMBER, contact.getNumber()); values.put(RecordDbContract.RecordItem.COLUMN_CONTACT_ID, contact.get_ID()); values.put(RecordDbContract.RecordItem.COLUMN_SIZE, generateNumber(100, 1)); values.put(RecordDbContract.RecordItem.COLUMN_DURATION, generateNumber(100, 1)); values.put(RecordDbContract.RecordItem.COLUMN_IS_INCOMING, generateBoolean()); values.put(RecordDbContract.RecordItem.COLUMN_IS_LOVE, generateBoolean()); values.put(RecordDbContract.RecordItem.COLUMN_IS_LOCKED, generateBoolean()); values.put(RecordDbContract.RecordItem.COLUMN_IS_TO_DELETE, generateBoolean()); mRecordsQueryHandler.startInsert(RecordsQueryHandler.INSERT_DEMO, null, RecordDbContract.CONTENT_URL, values); } }; // retrieve all contacts asyncQueryHandler.startQuery(0, null, uri, projection, selection, selectionArguments, orderBy); }