Java Code Examples for android.database.Cursor.getCount()

The following are Jave code examples for showing how to use getCount() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Farmacias   File: FindPresenter.java   Source Code and License Vote up 6 votes
private List<SuggestionsBean> transformQuickSearchCursor(Cursor data) {
    List<SuggestionsBean> list = new ArrayList<>(data.getCount());
    if (data.moveToFirst()) {
        do {

            SuggestionsBean suggestionsBean = new SuggestionsBean();
            suggestionsBean.setImageId(data.getInt(0));
            suggestionsBean.setName(data.getString(1));
            list.add(suggestionsBean);
        } while (data.moveToNext());
        //not forget to override hasCode and equals in SuggestionsBean class
        list =Observable.from(list).distinct().toList().toBlocking().first();
    }

    return list;
}
 
Example 2
Project: Reer   File: SQLiteHandle.java   Source Code and License Vote up 6 votes
public boolean queryHasFeed() {
    Log.i("sqlite", "开始");

    boolean isHasFeed;

    //开启事务
    db.beginTransaction();

    Cursor cursor = db.query("AllFeeds", null, null, null, null, null, null);

    if (cursor.getCount() != 0)
        isHasFeed = true;
    else
        isHasFeed = false;

    db.setTransactionSuccessful();
    db.endTransaction();

    return isHasFeed;
}
 
Example 3
Project: IslamicLibraryAndroid   File: AuthorRecyclerViewAdapter.java   Source Code and License Vote up 6 votes
public AuthorRecyclerViewAdapter(
        String IdColumnName,
        AuthorListFragment.OnAuthorItemClickListener listener,
        Context context,

        CursorListFragment cursorListFragment) {
    this.booksInformationDbHelper = BooksInformationDbHelper.getInstance(context);
    Cursor cursor = getCursor(
            cursorListFragment.shouldDisplayDownloadOnly(),
            cursorListFragment.getQueryString(),
            cursorListFragment.getCurrentSortIndex());
    this.context = context;
    this.cursorListFragment = cursorListFragment;
    init(cursor, cursor.getColumnIndex(IdColumnName));
    COLUMN_AUTHOUR_NAME_ID = cursor.getColumnIndexOrThrow(BooksInformationDBContract.AuthorEntry.COLUMN_NAME_NAME);
    COULMN_AUTHOUR_ID = cursor.getColumnIndexOrThrow(BooksInformationDBContract.AuthorEntry.COLUMN_NAME_ID);
    COLUMN_AUTHOUR_DEATH_DATE_ID = cursor.getColumnIndexOrThrow(BooksInformationDBContract.AuthorEntry.COLUMN_NAME_DEATH_HIJRI_YEAR);
    COULMN_NUMBER_OF_BOOKS = cursor.getColumnIndex(BooksInformationDBContract.AuthorEntry.COUNT_OF_BOOKS);
    COULMN_HAS_DOWNLOADED_BOOKS = cursor.getColumnIndex(BooksInformationDBContract.AuthorEntry.HAS_DOWNLOADED_BOOKS);
    itemCount = cursor.getCount();
    mListener = listener;
}
 
Example 4
Project: letv   File: DownloadManager.java   Source Code and License Vote up 6 votes
public static int getDownloadingVideoNum() {
    Cursor cursor = null;
    try {
        Query query = new Query(sConext.getContentResolver());
        query.setUri(DOWNLOAD_VIDEO_URI);
        query.setSelection("state != 4");
        cursor = query(query);
        int count = (cursor == null || cursor.getCount() <= 0) ? 0 : cursor.getCount();
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
        return count;
    } catch (Throwable th) {
        if (!(cursor == null || cursor.isClosed())) {
            cursor.close();
        }
    }
}
 
Example 5
Project: AIMSICDL   File: AIMSICDDbAdapter.java   Source Code and License Vote up 5 votes
/**
 * Check if CID (currently bts_id) is already in DBi_measure
 */
public boolean cellInDbiMeasure(int cellID) {
    String query = String.format(Locale.US,
            // "SELECT CID FROM DBi_bts, DBi_measure WHERE bts_id = %d", // todo E:V:A
            "SELECT bts_id FROM DBi_measure WHERE bts_id = %d",
            cellID);

    Cursor cursor = mDb.rawQuery(query, null);
    boolean exists = cursor.getCount() > 0;
    cursor.close();
    return exists;
}
 
Example 6
Project: PlusGram   File: userDBAdapter.java   Source Code and License Vote up 5 votes
private List<user> cursorToList(Cursor cursor) {
    List<user> items = new ArrayList();
    if (cursor.getCount() > 0) {
        while (cursor.moveToNext()) {
            user nam = new user();
            nam.setId(cursor.getInt(cursor.getColumnIndex(KEY_ID)));
            nam.setUid(cursor.getInt(cursor.getColumnIndex(KEY_UID)));
            nam.setFname(cursor.getString(cursor.getColumnIndex(KEY_FNAME)));
            nam.setLname(cursor.getString(cursor.getColumnIndex(KEY_LNAME)));
            nam.setUsername(cursor.getString(cursor.getColumnIndex(KEY_USERNAME)));
            nam.setPic(cursor.getString(cursor.getColumnIndex(KEY_PIC)));
            nam.setStatus(cursor.getString(cursor.getColumnIndex(KEY_STATUS)));
            nam.setPhone(cursor.getString(cursor.getColumnIndex(KEY_PHONE)));
            nam.setUptime(cursor.getString(cursor.getColumnIndex(KEY_UPTIME)));
            nam.setIsupdate(cursor.getInt(cursor.getColumnIndex(KEY_ISUPDATE)));
            nam.setIsspecific(cursor.getInt(cursor.getColumnIndex(KEY_ISSPECEFIC)));
            nam.setPicup(cursor.getInt(cursor.getColumnIndex(KEY_PICUP)));
            nam.setStatusup(cursor.getInt(cursor.getColumnIndex(KEY_STATUSUP)));
            nam.setPhoneup(cursor.getInt(cursor.getColumnIndex(KEY_PHONEUP)));
            nam.setIsonetime(cursor.getInt(cursor.getColumnIndex(KEY_ISONETIME)));


            items.add(nam);
        }
    }
    return items;
}
 
Example 7
Project: nucleus-test   File: UserDAO.java   Source Code and License Vote up 5 votes
public boolean cpfCadastrado(User user){
    String sql = "SELECT cpf FROM " + TABELA + " WHERE cpf=" + user.getCpf() +";";
    Cursor cursor = getReadableDatabase().rawQuery(sql, null);
    if (cursor.getCount() > 0){
        cursor.close();
        return true;
    } else{
        cursor.close();
        return false;
    }
}
 
Example 8
Project: Watermark   File: MediaUtils.java   Source Code and License Vote up 5 votes
/**
 * 根据地址获取视频相关信息
 */
public static MediaBean getMediaBeanWithVideo(Context context, String originalPath) {
    ContentResolver contentResolver = context.getContentResolver();
    List<String> projection = new ArrayList<>();
    projection.add(MediaStore.Video.Media._ID);
    projection.add(MediaStore.Video.Media.TITLE);
    projection.add(MediaStore.Video.Media.DATA);
    projection.add(MediaStore.Video.Media.BUCKET_ID);
    projection.add(MediaStore.Video.Media.BUCKET_DISPLAY_NAME);
    projection.add(MediaStore.Video.Media.MIME_TYPE);
    projection.add(MediaStore.Video.Media.DATE_ADDED);
    projection.add(MediaStore.Video.Media.DATE_MODIFIED);
    projection.add(MediaStore.Video.Media.LATITUDE);
    projection.add(MediaStore.Video.Media.LONGITUDE);
    projection.add(MediaStore.Video.Media.SIZE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        projection.add(MediaStore.Video.Media.WIDTH);
        projection.add(MediaStore.Video.Media.HEIGHT);
    }
    Cursor cursor = contentResolver.query(
            MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            projection.toArray(new String[projection.size()]),
            MediaStore.Images.Media.DATA + "=?",
            new String[]{originalPath}, null);
    MediaBean mediaBean = null;
    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();
        mediaBean = parseVideoCursorAndCreateThumImage(context, cursor);
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return mediaBean;
}
 
Example 9
Project: aos-MediaLib   File: MusicStoreImportImpl.java   Source Code and License Vote up 5 votes
/** copies data from Android's media db to ours */
private static int copyData (ContentResolver cr, String minId) {
    int imported = 0;
    String where = WHERE_ALL;
    String[] whereArgs = null;
    if (minId != null)  {
        where = WHERE_MIN_ID;
        whereArgs = new String[] { minId };
    }
    Cursor allFiles = CustomCursor.wrap(cr.query(MediaStore.Files.getContentUri("external"),
            FILES_PROJECTION, where, whereArgs, BaseColumns._ID));
    if (allFiles != null) {
        int count = allFiles.getCount();
        int ccount = allFiles.getColumnCount();
        if (count > 0) {
            // transaction size limited, acts like buffered output stream and auto-flushes queue
            BulkInserter inserter = new BulkInserter(MusicStoreInternal.FILES_IMPORT, cr, 2000);
            if (DBG) Log.d(TAG, "found items to import:" + count);
            while (allFiles.moveToNext()) {
                ContentValues cv = new ContentValues(ccount);
                DatabaseUtils.cursorRowToContentValues(allFiles, cv);
                inserter.add(cv);
            }
            imported = inserter.execute();
        }
        allFiles.close();
    }
    return imported;
}
 
Example 10
Project: mobile-store   File: RepoProvider.java   Source Code and License Vote up 5 votes
private static Repo cursorToRepo(Cursor cursor) {
    Repo repo = null;
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            repo = new Repo(cursor);
        }
        cursor.close();
    }
    return repo;
}
 
Example 11
Project: Hello-Music-droid   File: MusicService.java   Source Code and License Vote up 5 votes
private boolean makeAutoShuffleList() {
    Cursor cursor = null;
    try {
        cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{
                        MediaStore.Audio.Media._ID
                }, MediaStore.Audio.Media.IS_MUSIC + "=1", null, null);
        if (cursor == null || cursor.getCount() == 0) {
            return false;
        }
        final int len = cursor.getCount();
        final long[] list = new long[len];
        for (int i = 0; i < len; i++) {
            cursor.moveToNext();
            list[i] = cursor.getLong(0);
        }
        mAutoShuffleList = list;
        return true;
    } catch (final RuntimeException e) {
    } finally {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
    }
    return false;
}
 
Example 12
Project: GitHub   File: ContentProviderSimpleAdapter.java   Source Code and License Vote up 5 votes
private ContentProviderSimpleAdapter(final Uri baseProvider, Context context) {
  String[] projection = {MediaStore.Images.Media._ID};
  Cursor cursor = context.getContentResolver()
          .query(baseProvider, projection, null, null, null);
  final int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
  mUris = new Uri[cursor.getCount()];
  int i = 0;
  while (cursor.moveToNext()) {
    final String imageId = cursor.getString(columnIndex);
    mUris[i++] = Uri.withAppendedPath(baseProvider, imageId);
  }
  cursor.close();
}
 
Example 13
Project: Rey-MusicPlayer   File: MusicUtils.java   Source Code and License Vote up 5 votes
public static void setRingtone(AppCompatActivity context, long id) {
    if (!checkSystemWritePermission(context)) return;

    ContentResolver resolver = context.getContentResolver();
    Uri ringUri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id);

    try {
        ContentValues values = new ContentValues(2);
        values.put(MediaStore.Audio.Media.IS_RINGTONE, "1");
        values.put(MediaStore.Audio.Media.IS_ALARM, "1");
        resolver.update(ringUri, values, null, null);
    } catch (UnsupportedOperationException ex) {
        Log.e("Notset", "couldn't set ringtone flag for id " + id);
        return;
    }

    String[] cols = new String[]{
            MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.TITLE
    };

    String where = MediaStore.Audio.Media._ID + "=" + id;
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            cols, where, null, null);
    try {
        if (cursor != null && cursor.getCount() == 1) {
            cursor.moveToFirst();
            Settings.System.putString(resolver, Settings.System.RINGTONE, ringUri.toString());
            String message = context.getString(R.string.ringtone_set);
            String filename = '"' + cursor.getString(2) + '"';
            Toast.makeText(context, filename + " " + message, Toast.LENGTH_SHORT).show();
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
Example 14
Project: mobile-store   File: AppProvider.java   Source Code and License Vote up 5 votes
static List<App> cursorToList(Cursor cursor) {
    int knownAppCount = cursor != null ? cursor.getCount() : 0;
    List<App> apps = new ArrayList<>(knownAppCount);
    if (cursor != null) {
        if (knownAppCount > 0) {
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                apps.add(new App(cursor));
                cursor.moveToNext();
            }
        }
        cursor.close();
    }
    return apps;
}
 
Example 15
Project: letv   File: WorldCupTraceHandler.java   Source Code and License Vote up 5 votes
public int getWorldCupTraceNumExceptStatus(int status) {
    Cursor cursor = null;
    try {
        cursor = this.context.getContentResolver().query(LetvContentProvider.URI_WORLDCUPTRACE, null, "finish!=?", new String[]{status + ""}, "timestamp ASC");
        int count = cursor.getCount();
        return count;
    } finally {
        LetvTools.closeCursor(cursor);
    }
}
 
Example 16
Project: android_firebase_green_thumb   File: PurchaseActivity.java   Source Code and License Vote up 5 votes
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mPurchaseAdapter.swapCursor(data);

    boolean emptyPurchases = data.getCount() == 0;
    mTextViewPurchaseEmpty.setVisibility(emptyPurchases ? View.VISIBLE : View.GONE);
}
 
Example 17
Project: Andela-ALC-Challenge   File: UserDataSource.java   Source Code and License Vote up 5 votes
/**
 * Check if User are empty
 */
public boolean isUserEmpty() {

    boolean isEmpty = true;
    Cursor cursor = database.query(DatabaseHelper.TABLE_USER,
            allColumns, null, null, null, null, null);
    if (cursor != null && cursor.getCount() > 0) {
        isEmpty = false;
    }
    cursor.close();

    return isEmpty;
}
 
Example 18
Project: Misc   File: MessageUtils.java   Source Code and License Vote up 4 votes
/**
     * Get contact information about the given name.
     *
     * @param context The calling context.
     * @param name    The name.
     * @return The information or null on failure.
     */
    static String getContactInfo(Context context, String name) {
        if (name == null || name.length() == 0) {
            return null;
        }
        String info = "Contact Information for " + name + "\n";
        Cursor cursor = context.getContentResolver().query(
                ContactsContract.Contacts.CONTENT_URI, null, null,
                null, null);
        if (cursor == null) return null;
        if (cursor.getCount() == 0) {
            info += name + " not found\n";
            cursor.close();
            return info;
        }
        int indexId = cursor.getColumnIndex(COL_ID);
        String displayName;
        boolean found = false;
        if (cursor.moveToFirst()) {
            do {
                displayName = cursor
                        .getString(cursor
                                .getColumnIndex(ContactsContract.Contacts
                                        .DISPLAY_NAME));
                if (name.equals(displayName)) {
                    found = true;
                    break;
                }
            } while (cursor.moveToNext());
        }
        if (!found) {
            // The name was not found
            cursor.close();
            return null;
        }

        // Show additional info
        String id = cursor.getString(indexId);
        info += "_id: " + id + "\n";
        // ContactsContract.ContactsColumns.CONTACT_LAST_UPDATED_TIMESTAMP
        // Added in API 18
        info += getTimestampInfoForColumnName(cursor,
                "contact_last_updated_timestamp");
        info += getInfoForColumnName(cursor, ContactsContract.Contacts
                .PHOTO_ID);

        // These are apparently not kept track of on the EVO 3D or Galaxy S7
//        info += getInfoForColumnName(cursor,
//                ContactsContract.Contacts.TIMES_CONTACTED);
//        info += getInfoForColumnName(cursor,
//                ContactsContract.Contacts.LAST_TIME_CONTACTED);

        // Raw contacts
        Cursor rawCursor = context.getContentResolver().query
                (ContactsContract.RawContacts.CONTENT_URI,
                        null,
                        ContactsContract.RawContacts.CONTACT_ID + " = ?",
                        new String[]{id}, null);
        if (rawCursor != null) {
            info += "Linked contacts: " + rawCursor.getCount() + "\n";
            while (rawCursor.moveToNext()) {
                info += getRawContactDetails(context, rawCursor);
            }
            rawCursor.close();
        }

        cursor.close();
        return info;
    }
 
Example 19
Project: AssistantBySDK   File: LocalAudioDataSource.java   Source Code and License Vote up 4 votes
/**
 * 查询系统音频数据库,请慎用,
 * 建议使用{@linkplain com.lingju.assistant.player.audio.model.AudioRepository#findByListType(int)}  findByListType(local)}查询
 *
 * @return
 */
public List<PlayMusic> getLocal() {
    Log.i(LocalAudioDataSource.class.getName(), "getLocal>>>");
    ContentResolver cr = mContext.getContentResolver();
    Cursor cursor = null;
    List<PlayMusic> list = new PlayList<PlayMusic>();
    if (cr != null) {
        try {
            cursor = cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[]{
                            MediaStore.Audio.Media._ID,
                            MediaStore.Audio.Media.TITLE,
                            MediaStore.Audio.Media.DATA,
                            MediaStore.Audio.Media.DURATION,
                            MediaStore.Audio.Media.SIZE,
                            MediaStore.Audio.Media.ALBUM,
                            MediaStore.Audio.Media.ARTIST
                    },
                    MediaStore.Audio.Media.DURATION + ">?",
                    new String[]{MIN_AUDIO_SIZE},
                    MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
            int count = cursor.getCount();
            PlayMusic m = null;
            if (count > 0) {
                for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                    m = new PlayMusic();
                    m.setMusicid(Integer.toString(cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media._ID))));
                    m.setTitle(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)));
                    m.setUri(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA)));
                    m.setDuration(cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION)));
                    m.setSize(cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.SIZE)));
                    m.setSinger(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST)));
                    m.setAlbum(cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM)));
                    m.setCreated(new Timestamp(System.currentTimeMillis()));
                    list.add(m);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
    return list;
}
 
Example 20
Project: multiselect   File: MultiSelectActivity.java   Source Code and License Vote up 4 votes
private ArrayList<Integer> getInitSelectionList(Cursor data) {
  Integer[] integers = new Integer[data.getCount()];
  Arrays.fill(integers, View.GONE);
  return new ArrayList<>(Arrays.asList(integers));
}