Example usage for android.database Cursor isAfterLast

List of usage examples for android.database Cursor isAfterLast

Introduction

In this page you can find the example usage for android.database Cursor isAfterLast.

Prototype

boolean isAfterLast();

Source Link

Document

Returns whether the cursor is pointing to the position after the last row.

Usage

From source file:org.mariotaku.twidere.util.DataStoreUtils.java

@NonNull
public static UserKey[] getActivatedAccountKeys(@NonNull final Context context) {
    final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI,
            new String[] { Accounts.ACCOUNT_KEY }, Accounts.IS_ACTIVATED + " = 1", null, null);
    if (cur == null)
        return new UserKey[0];
    try {/*from   w w  w  . j a  v  a2  s.  co  m*/
        cur.moveToFirst();
        final UserKey[] ids = new UserKey[cur.getCount()];
        int i = 0;
        while (!cur.isAfterLast()) {
            ids[i++] = UserKey.valueOf(cur.getString(0));
            cur.moveToNext();
        }
        return ids;
    } finally {
        cur.close();
    }
}

From source file:com.zhu.searchexternalstoragedirectory.LocalMusicFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case LOADER_ID:
        // ??????
        String ringName1;//  ww  w  . j a  v a2 s.  c  o  m

        // ??List
        List<Map<String, String>> list = new ArrayList<>();
        // ??Set
        HashSet<String> set = new HashSet<>();

        if (cursor != null) {
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                // ??
                String ringName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                // ??
                String ringUrl = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
                if (ringName != null) {
                    // ?????[.amr]?
                    if (!set.contains(ringName) && !ringUrl.contains("/WeaAlarmClock/audio/record")
                            && !ringName.equals("record_start.mp3") && !ringName.equals("record_stop.mp3")
                            && !ringName.equals("ring_weac_alarm_clock_default.mp3")) {
                        // ???
                        set.add(ringName);
                        // ??
                        ringName = MyUtil.removeEx(ringName);
                        Map<String, String> map = new HashMap<>();
                        map.put(WeacConstants.RING_NAME, ringName);
                        map.put(WeacConstants.RING_URL, ringUrl);
                        list.add(map);
                        //                                // ????
                        //                                if (ringName.equals(ringName1)) {
                        //                                    mPosition = list.size() - 1;
                        //                                    RingSelectItem.getInstance().setRingPager(1);
                        //                                }
                    }
                }
            }
        }

        mLocalMusicAdapter = new RingSelectAdapter(getActivity(), list);
        setListAdapter(mLocalMusicAdapter);
        setSelection(mPosition);
        break;
    }
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getBookmarksInBook(BibleBook book) {
    Log.d(TAG, "about to getBookmarksInPassage:" + book.getOSIS());
    List<BookmarkDto> bookmarkList = new ArrayList<BookmarkDto>();
    //av11n TODO may need to map between different versifications here
    Cursor c = db.query(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS, BookmarkColumn.KEY + " LIKE ?",
            new String[] { String.valueOf(book.getOSIS() + ".%") }, null, null, null);
    try {// www .j av  a2  s  . c om
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                bookmarkList.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    Log.d(TAG, "bookmarksInPassage set to " + bookmarkList.size() + " item long list");
    return bookmarkList;
}

From source file:de.elanev.studip.android.app.frontend.courses.CourseOverviewFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {

    if (getActivity() == null) {
        return;/*  w w  w .  ja v a 2 s  .  co m*/
    }
    cursor.moveToFirst();

    int loaderId = loader.getId();
    switch (loaderId) {
    case COURSE_LOADER:

        if (!cursor.isAfterLast()) {
            String courseTitle = cursor
                    .getString(cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_TITLE));
            String courseDescription = cursor
                    .getString(cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_DESCIPTION));
            int courseTyp = cursor.getInt(cursor.getColumnIndex(CoursesContract.Columns.Courses.COURSE_TYPE));

            mTitleTextView.setText(courseTitle);
            getActivity().setTitle(courseTitle);
            String courseTypeString = Settings
                    .fromJson(Prefs.getInstance(getActivity()).getApiSettings()).semTypes.get(courseTyp).name;
            mCourseTypeTextView.setText(courseTypeString);
            if (!TextUtils.isEmpty(courseDescription)) {
                mDescriptionTextView.setText(courseDescription);
                mDescriptionTextView.setMovementMethod(new ScrollingMovementMethod());
            }

        }
        break;
    case COURSE_EVENTS_LOADER:
        if (cursor.getCount() >= 1) {

            String room = cursor.getString(cursor.getColumnIndex(EventsContract.Columns.EVENT_ROOM));
            String title = cursor.getString(cursor.getColumnIndex(EventsContract.Columns.EVENT_TITLE));
            mNextAppointmentTextView.setText(String.format("%s\n%s", title, room));
        }

        break;
    case COURSE_NEWS_LOADER:
        if (cursor.getCount() >= 1) {

            final String newsTopic = cursor.getString(cursor.getColumnIndex(NewsContract.Columns.NEWS_TOPIC));
            final Long newsDate = cursor.getLong(cursor.getColumnIndex(NewsContract.Columns.NEWS_MKDATE));
            final String newsBody = cursor.getString(cursor.getColumnIndex(NewsContract.Columns.NEWS_BODY));
            final String userForename = cursor
                    .getString(cursor.getColumnIndex(UsersContract.Columns.USER_FORENAME));
            final String userLastname = cursor
                    .getString(cursor.getColumnIndex(UsersContract.Columns.USER_LASTNAME));

            mNewsTitleTextView.setText(newsTopic);
            mNewsAuthorTextView.setText(TextTools.getLocalizedAuthorAndDateString(
                    String.format("%s %s", userForename, userLastname), newsDate, getActivity()));
            mNewsAuthorTextView.setVisibility(View.VISIBLE);
            mNewsShowMoreTextView.setVisibility(View.VISIBLE);
            mNewsTextTextView.setText(Html.fromHtml(newsBody));

        }
        break;
    case COURSE_TEACHERS_LOADER:
        String teachersString;
        if (!cursor.isAfterLast()) {
            String teacherAvatarUrl = cursor
                    .getString(cursor.getColumnIndex(UsersContract.Columns.USER_AVATAR_NORMAL));
            teachersString = TextTools.createNameSting(
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_TITLE_PRE)),
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_FORENAME)),
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_LASTNAME)),
                    cursor.getString(cursor.getColumnIndex(UsersContract.Columns.USER_TITLE_POST)));
            mTeacherNameTextView.setText(teachersString);

            int teacherCount = cursor.getCount();
            if (teacherCount > 1) {
                teacherCount -= 1;
                mTeacherCountTextView
                        .setText(String.format(getString(R.string.and_more_teachers), teacherCount));
                mTeacherCountTextView.setVisibility(View.VISIBLE);
            }

            Picasso.with(mContext).load(teacherAvatarUrl)
                    .resizeDimen(R.dimen.user_image_icon_size, R.dimen.user_image_icon_size).centerCrop()
                    .placeholder(R.drawable.nobody_normal).into(mUserImageView);
        }
        break;
    }

}

From source file:de.elanev.studip.android.app.frontend.messages.MessagesListFragment.java

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;//  www .jav  a2s.  c  om
    }

    cursor.moveToFirst();
    if (cursor.getCount() > 0) {
        List<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>();
        if (!cursor.isAfterLast())
            getActivity().setTitle(cursor.getString(
                    cursor.getColumnIndex(MessagesContract.Columns.MessageFolders.MESSAGE_FOLDER_NAME)));

        long previousDay = -1;
        long currentDay = -1;
        while (!cursor.isAfterLast()) {
            currentDay = cursor
                    .getLong(cursor.getColumnIndex(MessagesContract.Columns.Messages.MESSAGE_MKDATE));
            if (!DateTools.isSameDay(previousDay * 1000L, currentDay * 1000L)) {
                sections.add(new SectionedCursorAdapter.Section(cursor.getPosition(),
                        TextTools.getLocalizedTime(currentDay * 1000L, mContext)));
            }

            previousDay = currentDay;

            cursor.moveToNext();
        }

        mMessagesAdapter.setSections(sections);
    }

    mMessagesAdapter.swapCursor(cursor);

    setLoadingViewVisible(false);
}

From source file:de.j4velin.picturechooser.ImagesFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.gallery, null);

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME },
            MediaStore.Images.Media.BUCKET_ID + " = ?",
            new String[] { String.valueOf(getArguments().getInt("bucket")) },
            MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> images = new ArrayList<GridItem>(cur.getCount());

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                images.add(new GridItem(cur.getString(1), cur.getString(0)));
                cur.moveToNext();//  w  w w .  j av a  2 s.  c  o m
            }
        }
        cur.close();
    }

    GridView grid = (GridView) v.findViewById(R.id.grid);
    grid.setAdapter(new GalleryAdapter(getActivity(), images));
    grid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ((Main) getActivity()).imageSelected(images.get(position).path);
        }
    });
    return v;
}

From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java

/**
 * Processes new data, adds notifications if any
 *
 * @param tickersList JSONObject with new tickers data
 * @param oldData     JSONObject with old tickers data
 * @return String with all notifications
 *///from ww  w  . jav  a 2 s  . c  o m
private String checkNotifiers(ArrayList<Ticker> tickersList, Map<String, Ticker> oldData) {

    DBWorker dbWorker = DBWorker.getInstance(this);
    Cursor cursor = dbWorker.getNotifiers();

    StringBuilder stringBuilder = new StringBuilder();
    for (Ticker ticker : tickersList) {
        cursor.moveToFirst();
        String pair = ticker.getPair();
        if (oldData.size() != 0 && oldData.containsKey(pair)) {
            double oldValue = oldData.get(pair).getLast();
            double newValue = ticker.getLast();
            while (!cursor.isAfterLast()) {
                boolean pairMatched = pair.replace("_", "/").toUpperCase(Locale.US)
                        .equals(cursor.getString(cursor.getColumnIndex("Pair")));
                if (pairMatched) {
                    float percent;
                    switch (cursor.getInt(cursor.getColumnIndex("Type"))) {
                    case PANIC_BUY_TYPE:
                        percent = cursor.getFloat(cursor.getColumnIndex("Value")) / 100;
                        if (newValue > ((1 + percent) * oldValue)) {
                            stringBuilder.append("Panic Buy for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    case PANIC_SELL_TYPE:
                        percent = cursor.getFloat(cursor.getColumnIndex("Value")) / 100;
                        if (newValue < ((1 - percent) * oldValue)) {
                            stringBuilder.append("Panic Sell for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    case STOP_LOSS_TYPE:
                        if (newValue < cursor.getFloat(cursor.getColumnIndex("Value"))) {
                            stringBuilder.append("Stop Loss for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    case TAKE_PROFIT_TYPE:
                        if (newValue > cursor.getFloat(cursor.getColumnIndex("Value"))) {
                            stringBuilder.append("Take Profit for ")
                                    .append(pair.replace("_", "/").toUpperCase(Locale.US)).append("; ");
                        }
                        break;
                    default:
                        break;
                    }
                }
                cursor.moveToNext();
            }
        }
    }
    cursor.close();
    return stringBuilder.toString();
}

From source file:lib.picturechooser.ImagesFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.gallery, null);

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME },
            MediaStore.Images.Media.BUCKET_ID + " = ?",
            new String[] { String.valueOf(getArguments().getInt("bucket")) },
            MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> images = new ArrayList<GridItem>(cur.getCount());

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                images.add(new GridItem(cur.getString(1), cur.getString(0)));
                cur.moveToNext();//w w  w  .j  a v a2s .  c om
            }
        }
        cur.close();
    }

    GridView grid = (GridView) v.findViewById(R.id.grid);
    grid.setAdapter(new GalleryAdapter(getActivity(), images));
    grid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ((SelectPictureActivity) getActivity()).imageSelected(images.get(position).path);
        }
    });
    return v;
}

From source file:com.andrew.apollo.menu.PlaylistDialog.java

private String nameForId(long id) {

    Cursor cursor = MusicUtils.query(this, Audio.Playlists.EXTERNAL_CONTENT_URI,
            new String[] { Audio.Playlists.NAME }, Audio.Playlists._ID + "=?",
            new String[] { Long.valueOf(id).toString() }, Audio.Playlists.NAME);
    String name = null;//from   w  w w .  ja  v a2s.  c  o m
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            name = cursor.getString(0);
        }
        cursor.close();
    }
    return name;
}

From source file:com.example.easyvoice.MessageDetail.java

public void LoadMessage(int msgId) {

    SQLiteDatabase db = null;/*from   w  w  w. j a  va2s  . co m*/
    try {
        db = this.openOrCreateDatabase(DB_NAME, MODE_PRIVATE, null);

        ContentValues values = new ContentValues();
        values.put("msg_id", msgId);

        String[] tableColumns = new String[] { "msg_id", "disp_name", "content" };
        String whereClause = "msg_id = ?";
        String[] whereArgs = new String[] { Integer.toString(msgId) };

        Cursor c = db.query(TABLE_NAME, tableColumns, whereClause, whereArgs, null, null, null);

        if (c != null) {
            Log.d(getClass().getSimpleName(), "cursor ok");

            boolean hasContents = c.moveToFirst();
            Log.i(getClass().getSimpleName(), "hasContents is " + hasContents);

            while (c.isAfterLast() == false) {

                Message m = new Message();

                int n = c.getColumnIndex("msg_id");
                Log.i(getClass().getSimpleName(), "reading column rowid, index is " + n);

                int rowid = c.getInt(n);
                m.setMsgId(rowid);

                Log.i(getClass().getSimpleName(), "reading column disp_name");
                m.setDispName(c.getString(c.getColumnIndex("disp_name")));
                Log.i(getClass().getSimpleName(), "reading column content");
                m.setContent(c.getString(c.getColumnIndex("content")));

                displayEdit.setText(m.getDispName());
                contentEdit.setText(m.getContent());
                /*      
                      map.put (pos, m);
                              
                      results.add(m.getDispName());
                */

                c.moveToNext();
            }
        }

        /*
        values.put("disp_name", displayEdit.getText ().toString());
        values.put("content",   contentEdit.getText ().toString());
        */
    } catch (SQLiteException se) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database (2)");
    }
}