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:de.j4velin.picturechooser.BucketsFragment.java

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

    String[] projection = new String[] { MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.BUCKET_ID };

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null, null, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " ASC, "
                    + MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> buckets = new ArrayList<GridItem>();
    BucketItem lastBucket = null;//from w w w.j a  v  a  2  s. c  o  m

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                if (lastBucket == null || !lastBucket.name.equals(cur.getString(1))) {
                    lastBucket = new BucketItem(cur.getString(1), cur.getString(0), cur.getInt(2));
                    buckets.add(lastBucket);
                } else {
                    lastBucket.images++;
                }
                cur.moveToNext();
            }
        }
        cur.close();
    }

    if (buckets.isEmpty()) {
        Toast.makeText(getActivity(), R.string.no_images, Toast.LENGTH_SHORT).show();
        getActivity().finish();
    } else {
        GridView grid = (GridView) v.findViewById(R.id.grid);
        grid.setAdapter(new GalleryAdapter(getActivity(), buckets));
        grid.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ((Main) getActivity()).showBucket(((BucketItem) buckets.get(position)).id);
            }
        });
    }
    return v;
}

From source file:org.sensapp.android.sensappdroid.activities.GraphDisplayerActivity.java

private void addGraphToWrapperList(List<GraphWrapper> gwl, Cursor cursor, String title, int style, int color,
        long graphSensorID, float min, float max) {
    GraphBuffer buffer = new GraphBuffer();
    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        buffer.insertData(cursor.getFloat(cursor.getColumnIndex(SensAppContract.Measure.VALUE)));
    }//from www  .  j a  v a  2  s .com

    GraphWrapper wrapper = new GraphWrapper(graphSensorID, buffer);
    if ((min == Integer.MIN_VALUE) || (max == Integer.MAX_VALUE)) {
        wrapper.setGraphOptions(color, 500, style, title);
        if (min != Integer.MIN_VALUE)
            wrapper.setLowestVisible(min);
        if (max != Integer.MAX_VALUE)
            wrapper.setHighestVisible(max);
    } else
        wrapper.setGraphOptions(color, 500, style, title, min, max);
    wrapper.setPrinterParameters(true, false, true);

    gwl.add(wrapper);
}

From source file:org.strongswan.android.data.VpnProfileDataSource.java

/**
 * Get a list of all VPN profiles stored in the database.
 * @return list of VPN profiles/*from w  ww  .  jav a2s .  c  o  m*/
 */
public List<VpnProfile> getAllVpnProfiles() {
    List<VpnProfile> vpnProfiles = new ArrayList<VpnProfile>();

    Cursor cursor = null;
    try {
        cursor = mDatabase.query(TABLE_VPNPROFILE, ALL_COLUMNS, null, null, null, null, null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            VpnProfile vpnProfile = VpnProfileFromCursor(cursor);
            vpnProfiles.add(vpnProfile);
            cursor.moveToNext();
        }
    } finally {
        closeCursor(cursor);
    }
    return vpnProfiles;
}

From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java

/**
 * Is patient row modified?/*from  w  ww. j ava2  s .  co  m*/
  * @param id ID
 * @return -1 if new, 0 if not modified, 1 if modified
 */
private int isPatientDirty(int id) {
    int dirty = -1;
    String query = "SELECT dirty FROM patient WHERE patient_id = ?;";
    Cursor cursor = mDatabase.rawQuery(query, new String[] { "" + id });
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        dirty = cursor.getInt(0);
    }
    cursor.close();
    return dirty;
}

From source file:com.im4j.picturebeautify.picchooser.BucketsFragment.java

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

    String[] projection = new String[] { MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.BUCKET_ID };

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null, null, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " ASC, "
                    + MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> buckets = new ArrayList<GridItem>();
    BucketItem lastBucket = null;//from  w  w w  .j a  va  2 s  .  co  m

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                if (lastBucket == null || !lastBucket.name.equals(cur.getString(1))) {
                    lastBucket = new BucketItem(cur.getString(1), cur.getString(0), "", cur.getInt(2));
                    buckets.add(lastBucket);
                } else {
                    lastBucket.images++;
                }
                cur.moveToNext();
            }
        }
        cur.close();
    }

    if (buckets.isEmpty()) {
        Toast.makeText(getActivity(), R.string.no_images, Toast.LENGTH_SHORT).show();
        getActivity().finish();
    } else {
        GridView grid = (GridView) v.findViewById(R.id.grid);
        grid.setAdapter(new GalleryAdapter(getActivity(), buckets));
        grid.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ((SelectPictureActivity) getActivity()).showBucket(((BucketItem) buckets.get(position)).id);
            }
        });
    }
    return v;
}

From source file:lib.picturechooser.BucketsFragment.java

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

    String[] projection = new String[] { MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.BUCKET_ID };

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null, null, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " ASC, "
                    + MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> buckets = new ArrayList<GridItem>();
    BucketItem lastBucket = null;//from  www . jav  a 2 s.c  om

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                if (lastBucket == null || !lastBucket.name.equals(cur.getString(1))) {
                    lastBucket = new BucketItem(cur.getString(1), cur.getString(0), cur.getInt(2));
                    buckets.add(lastBucket);
                } else {
                    lastBucket.images++;
                }
                cur.moveToNext();
            }
        }
        cur.close();
    }

    if (buckets.isEmpty()) {
        Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT).show();
        getActivity().finish();
    } else {
        GridView grid = (GridView) v.findViewById(R.id.grid);
        grid.setAdapter(new GalleryAdapter(getActivity(), buckets));
        grid.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ((SelectPictureActivity) getActivity()).showBucket(((BucketItem) buckets.get(position)).id);
            }
        });
    }
    return v;
}

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

@NonNull
public static UserKey[] getAccountKeys(final Context context) {
    if (context == null)
        return new UserKey[0];
    final String[] projection = { Accounts.ACCOUNT_KEY };
    final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, projection, null, null, null);
    if (cur == null)
        return new UserKey[0];
    try {/*from ww w .  j a v a  2 s . c  o  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.anysoftkeyboard.ui.settings.wordseditor.UserDictionaryEditorFragment.java

private void fillWordsList() {
    Log.d(TAG, "Selected locale is " + mSelectedLocale);
    new UserWordsEditorAsyncTask(this) {
        private EditableDictionary mNewDictionary;
        private List<UserWordsListAdapter.Word> mWordsList;

        @Override/*from  ww w.j  a  v a 2 s  . c  om*/
        protected void onPreExecute() {
            super.onPreExecute();
            // all the code below can be safely (and must) be called in the
            // UI thread.
            mNewDictionary = getEditableDictionary(mSelectedLocale);
            if (mNewDictionary != mCurrentDictionary && mCurrentDictionary != null && mCursor != null) {
                mCurrentDictionary.close();
            }
        }

        @Override
        protected Void doAsyncTask(Void[] params) throws Exception {
            mCurrentDictionary = mNewDictionary;
            mCurrentDictionary.loadDictionary();
            mCursor = mCurrentDictionary.getWordsCursor();
            Cursor cursor = mCursor.getCursor();
            mWordsList = new ArrayList<>(mCursor.getCursor().getCount());
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                UserWordsListAdapter.Word word = new UserWordsListAdapter.Word(mCursor.getCurrentWord(),
                        mCursor.getCurrentWordFrequency());
                mWordsList.add(word);
                cursor.moveToNext();
            }
            //now, sorting the word list alphabetically
            Collections.sort(mWordsList, msWordsComparator);
            return null;
        }

        protected void applyResults(Void result, Exception backgroundException) {
            ListAdapter adapter = getWordsListAdapter(mWordsList);
            //AbsListView introduced the setAdapter method in API11, so I'm required to check the instance type
            if (mWordsListView instanceof ListView) {
                //this is NOT a redundant cast!
                ((ListView) mWordsListView).setAdapter(adapter);
            } else if (mWordsListView instanceof GridView) {
                //this is NOT a redundant cast!
                ((GridView) mWordsListView).setAdapter(adapter);
            } else {
                throw new ClassCastException("Unknown mWordsListView type " + mWordsListView.getClass());
            }
        }
    }.execute();
}

From source file:com.soundcloud.android.crop.support.BucketsFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.gallery, null);
    Toolbar toolbar = (Toolbar) v.findViewById(R.id.toolbar);
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override/*from   ww  w  . jav a2s  .  c  om*/
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });

    String[] projection = new String[] { MediaStore.Images.Media.DATA,
            MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.BUCKET_ID };

    Cursor cur = getActivity().getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null, null, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " ASC, "
                    + MediaStore.Images.Media.DATE_MODIFIED + " DESC");

    final List<GridItem> buckets = new ArrayList<GridItem>();
    BucketItem lastBucket = null;

    if (cur != null) {
        if (cur.moveToFirst()) {
            while (!cur.isAfterLast()) {
                if (lastBucket == null || !lastBucket.name.equals(cur.getString(1))) {
                    lastBucket = new BucketItem(cur.getString(1), cur.getString(0), "", cur.getInt(2));
                    buckets.add(lastBucket);
                } else {
                    lastBucket.images++;
                }
                cur.moveToNext();
            }
        }
        cur.close();
    }

    if (buckets.isEmpty()) {
        Toast.makeText(getActivity(), R.string.no_images, Toast.LENGTH_SHORT).show();
        getActivity().finish();
    } else {
        GridView grid = (GridView) v.findViewById(R.id.grid);
        grid.setAdapter(new GalleryAdapter(getActivity(), buckets));
        grid.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                ((SelectPictureActivity) getActivity()).showBucket(((BucketItem) buckets.get(position)).id);
            }
        });
    }
    return v;
}

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

public static String[] getAccountScreenNames(@NonNull final Context context,
        @Nullable final UserKey[] accountKeys) {
    final String[] cols = new String[] { Accounts.SCREEN_NAME };
    final String where;
    final String[] whereArgs;
    if (accountKeys != null) {
        where = Expression.inArgs(new Column(Accounts.ACCOUNT_KEY), accountKeys.length).getSQL();
        whereArgs = TwidereArrayUtils.toStringArray(accountKeys);
    } else {//from w  w  w  .ja  va  2 s  . c o  m
        where = null;
        whereArgs = null;
    }
    final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, cols, where, whereArgs, null);
    if (cur == null)
        return new String[0];
    try {
        cur.moveToFirst();
        final String[] screen_names = new String[cur.getCount()];
        int i = 0;
        while (!cur.isAfterLast()) {
            screen_names[i++] = cur.getString(0);
            cur.moveToNext();
        }
        return screen_names;
    } finally {
        cur.close();
    }
}