Example usage for android.database Cursor isLast

List of usage examples for android.database Cursor isLast

Introduction

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

Prototype

boolean isLast();

Source Link

Document

Returns whether the cursor is pointing to the last row.

Usage

From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java

/**
 * For the current track identifier the route of that track is drawn by
 * adding a OverLay for each segments in the track
 *//*from w ww.  j  av  a  2s  .  c om*/
private void createDataOverlays() {
    mLastSegmentOverlay = null;
    resetOverlay();
    setupHardwareAcceleration();

    ContentResolver resolver = this.getContentResolver();
    Cursor segments = null;
    int trackColoringMethod = Integer.valueOf(mSharedPreferences.getString(Constants.TRACKCOLORING, "2"))
            .intValue();

    try {
        Uri segmentsUri = Uri.withAppendedPath(Tracks.CONTENT_URI, this.mTrackId + "/segments");
        segments = resolver.query(segmentsUri, new String[] { Segments._ID }, null, null, null);
        if (segments != null && segments.moveToFirst()) {
            do {
                long segmentsId = segments.getLong(0);
                Uri segmentUri = ContentUris.withAppendedId(segmentsUri, segmentsId);
                SegmentOverlay segmentOverlay = new SegmentOverlay(this, segmentUri, trackColoringMethod,
                        mAverageSpeed, this.mMapView, mHandler);
                mMapView.getOverlays().add(segmentOverlay);
                mLastSegmentOverlay = segmentOverlay;
                if (segments.isFirst()) {
                    segmentOverlay.addPlacement(SegmentOverlay.FIRST_SEGMENT);
                }
                if (segments.isLast()) {
                    segmentOverlay.addPlacement(SegmentOverlay.LAST_SEGMENT);
                }
                mLastSegment = segmentsId;
            } while (segments.moveToNext());
        }
    } finally {
        if (segments != null) {
            segments.close();
        }
    }

    Uri lastSegmentUri = Uri.withAppendedPath(Tracks.CONTENT_URI,
            mTrackId + "/segments/" + mLastSegment + "/waypoints");
    resolver.unregisterContentObserver(this.mSegmentWaypointsObserver);
    resolver.registerContentObserver(lastSegmentUri, false, this.mSegmentWaypointsObserver);
}

From source file:com.android.bluetooth.map.BluetoothMapContent.java

private String setWhereFilterPhones(String str) {
    String where = "";
    str = str.replace("*", "%");

    Cursor c = mResolver.query(ContactsContract.Contacts.CONTENT_URI, null,
            ContactsContract.Contacts.DISPLAY_NAME + " like ?", new String[] { str },
            ContactsContract.Contacts.DISPLAY_NAME + " ASC");

    try {//ww w.j a  v  a  2 s  . co  m
        while (c != null && c.moveToNext()) {
            String contactId = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));

            Cursor p = mResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { contactId },
                    null);

            try {
                while (p != null && p.moveToNext()) {
                    String number = p
                            .getString(p.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                    where += " address = " + "'" + number + "'";
                    if (!p.isLast())
                        where += " OR ";
                }
            } finally {
                close(p);
            }

            if (!c.isLast())
                where += " OR ";
        }
    } finally {
        close(c);
    }

    if (str != null && str.length() > 0) {
        if (where.length() > 0) {
            where += " OR ";
        }
        where += " address like " + "'" + str + "'";
    }

    return where;
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Creates new {@link #mFileSelector} to select appropriate file after
 * loading a folder's content. It's either the parent path of last path, or
 * the file provided by key {@link FileChooserActivity#EXTRA_SELECT_FILE}.
 * Note that this also cancels previous selector if there is such one.
 *//*from   w ww.  ja v  a  2  s.c  o  m*/
private void createFileSelector() {
    if (mFileSelector != null)
        mFileSelector.cancel(true);

    mFileSelector = new LoadingDialog<Void, Void, Integer>(getActivity(), true) {

        @Override
        protected Integer doInBackground(Void... params) {
            final Cursor cursor = mFileAdapter.getCursor();
            if (cursor == null || cursor.isClosed())
                return -1;

            final Uri selectedFile = (Uri) getArguments().getParcelable(FileChooserActivity.EXTRA_SELECT_FILE);
            final int colUri = cursor.getColumnIndex(BaseFile.COLUMN_URI);
            if (selectedFile != null)
                getArguments().remove(FileChooserActivity.EXTRA_SELECT_FILE);

            int shouldBeSelectedIdx = -1;
            final Uri uri = selectedFile != null ? selectedFile : getLastLocation();
            if (uri == null || !BaseFileProviderUtils.fileExists(getActivity(), uri))
                return -1;

            final String fileName = BaseFileProviderUtils.getFileName(getActivity(), uri);
            if (fileName == null)
                return -1;

            Uri parentUri = BaseFileProviderUtils.getParentFile(getActivity(), uri);
            if ((uri == getLastLocation() && !getCurrentLocation().equals(getLastLocation())
                    && BaseFileProviderUtils.isAncestorOf(getActivity(), getCurrentLocation(), uri))
                    || getCurrentLocation().equals(parentUri)) {
                if (cursor.moveToFirst()) {
                    while (!cursor.isLast()) {
                        if (isCancelled())
                            return -1;

                        Uri subUri = Uri.parse(cursor.getString(colUri));
                        if (uri == getLastLocation()) {
                            if (cursor.getInt(cursor
                                    .getColumnIndex(BaseFile.COLUMN_TYPE)) == BaseFile.FILE_TYPE_DIRECTORY) {
                                if (subUri.equals(uri)
                                        || BaseFileProviderUtils.isAncestorOf(getActivity(), subUri, uri)) {
                                    shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                    break;
                                }
                            }
                        } else {
                            if (uri.equals(subUri)) {
                                shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                break;
                            }
                        }

                        cursor.moveToNext();
                    } // while
                } // if
            } // if

            return shouldBeSelectedIdx;
        }// doInBackground()

        @Override
        protected void onPostExecute(final Integer result) {
            super.onPostExecute(result);

            if (isCancelled() || mFileAdapter.isEmpty())
                return;

            /*
             * Use a Runnable to make sure this works. Because if the list
             * view is handling data, this might not work.
             * 
             * Also sometimes it doesn't work without a delay.
             */
            mViewFiles.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (result >= 0 && result < mFileAdapter.getCount())
                        mViewFiles.setSelection(result);
                    else if (!mFileAdapter.isEmpty())
                        mViewFiles.setSelection(0);
                }// run()
            }, DisplayPrefs.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    };

    mFileSelector.execute();
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Creates new {@link #mFileSelector} to select appropriate file after
 * loading a folder's content. It's either the parent path of last path, or
 * the file provided by key {@link FileChooserActivity#EXTRA_SELECT_FILE}.
 * Note that this also cancels previous selector if there is such one.
 *//* w w w. j  av a 2  s .  co m*/
private void createFileSelector() {
    if (mFileSelector != null)
        mFileSelector.cancel(true);

    mFileSelector = new LoadingDialog<Void, Void, Integer>(getActivity(), true) {

        @Override
        protected Integer doInBackground(Void... params) {
            final Cursor cursor = mFileAdapter.getCursor();
            if (cursor == null || cursor.isClosed())
                return -1;

            final Uri selectedFile = (Uri) getArguments().getParcelable(FileChooserActivity.EXTRA_SELECT_FILE);
            final int colUri = cursor.getColumnIndex(BaseFile.COLUMN_URI);
            if (selectedFile != null)
                getArguments().remove(FileChooserActivity.EXTRA_SELECT_FILE);

            int shouldBeSelectedIdx = -1;
            final Uri uri = selectedFile != null ? selectedFile : getLastLocation();
            if (uri == null || !BaseFileProviderUtils.fileExists(getActivity(), uri))
                return -1;

            final String fileName = BaseFileProviderUtils.getFileName(getActivity(), uri);
            if (fileName == null)
                return -1;

            Uri parentUri = BaseFileProviderUtils.getParentFile(getActivity(), uri);
            if ((uri == getLastLocation() && !getCurrentLocation().equals(getLastLocation())
                    && BaseFileProviderUtils.isAncestorOf(getActivity(), getCurrentLocation(), uri))
                    || getCurrentLocation().equals(parentUri)) {
                if (cursor.moveToFirst()) {
                    while (!cursor.isLast()) {
                        if (isCancelled())
                            return -1;

                        Uri subUri = Uri.parse(cursor.getString(colUri));
                        if (uri == getLastLocation()) {
                            if (cursor.getInt(cursor
                                    .getColumnIndex(BaseFile.COLUMN_TYPE)) == BaseFile.FILE_TYPE_DIRECTORY) {
                                if (subUri.equals(uri)
                                        || BaseFileProviderUtils.isAncestorOf(getActivity(), subUri, uri)) {
                                    shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                    break;
                                }
                            }
                        } else {
                            if (uri.equals(subUri)) {
                                shouldBeSelectedIdx = Math.max(0, cursor.getPosition() - 2);
                                break;
                            }
                        }

                        cursor.moveToNext();
                    } // while
                } // if
            } // if

            return shouldBeSelectedIdx;
        }// doInBackground()

        @Override
        protected void onPostExecute(final Integer result) {
            super.onPostExecute(result);

            if (isCancelled() || mFileAdapter.isEmpty())
                return;

            /*
             * Use a Runnable to make sure this works. Because if the list
             * view is handling data, this might not work.
             * 
             * Also sometimes it doesn't work without a delay.
             */
            mViewFiles.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (result >= 0 && result < mFileAdapter.getCount())
                        mViewFiles.setSelection(result);
                    else if (!mFileAdapter.isEmpty())
                        mViewFiles.setSelection(0);
                }// run()
            }, Display.DELAY_TIME_FOR_VERY_SHORT_ANIMATION);
        }// onPostExecute()

    };

    mFileSelector.execute();
}

From source file:cz.maresmar.sfm.view.MainActivity.java

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case USER_LOADER_ID: {
        Timber.d("User data loaded");

        // Removes old profiles
        mProfiles.clear();/*  ww w .  ja v a2  s . c  o m*/

        // Insert new profiles
        if (cursor.moveToFirst()) {
            do {
                Long userId = cursor.getLong(0);
                String userName = cursor.getString(1);
                Uri iconUri = Uri.parse(cursor.getString(2));

                ProfileDrawerItem profile = new ProfileDrawerItem().withIdentifier(userId).withName(userName)
                        .withIcon(iconUri);
                mProfiles.addProfiles(profile);
            } while (cursor.moveToNext());
        }

        // Select default user
        if (mSelectedUserId == SettingsContract.LAST_USER_UNKNOWN && mProfiles.getActiveProfile() != null) {
            mSelectedUserId = mProfiles.getActiveProfile().getIdentifier();
        }

        // Set last user in UI
        if (mSelectedUserId != SettingsContract.LAST_USER_UNKNOWN) {
            mProfiles.setActiveProfile(mSelectedUserId);
        }

        // Insert control entries
        mProfiles.addProfiles(ADD_USER_DRAWER_ITEM, MANAGE_USER_DRAWER_ITEM);

        // Load correct user info for selected user (could be from backup)
        Loader portalLoader = getSupportLoaderManager().getLoader(PORTAL_LOADER_ID);
        if (portalLoader == null || !portalLoader.isStarted()) {
            getSupportLoaderManager().initLoader(PORTAL_LOADER_ID, null, this);
            getSupportLoaderManager().initLoader(EDIT_ACTIONS_COUNT_LOADER_ID, null, this);
        }
        // Should be always reused because of users recreation
        getSupportLoaderManager().initLoader(CREDENTIAL_LOADER_ID, null, this);
        break;
    }
    case PORTAL_LOADER_ID: {
        Timber.d("Portal data loaded");

        // Clear old portals
        int oldPortalCount = mPortalDrawerItem.getSubItems().size();
        mPortalDrawerItem.getSubItems().clear();

        // Insert new portals
        boolean selectedFound = false;
        if (cursor.moveToFirst()) {
            do {
                Long portalId = cursor.getLong(0);
                String portalName = cursor.getString(1);
                int credit = cursor.getInt(2);

                SecondaryDrawerItem portalItem = new SecondaryDrawerItem().withIdentifier(portalId)
                        .withName(portalName).withDescription(MenuUtils.getPriceStr(this, credit))
                        .withTag(PORTAL_ITEM_DRAWER_TAG);

                // Updates selected fragment if new user hasn't the old one
                if (portalId == mSelectedFragmentId) {
                    portalItem.withSetSelected(true);
                    setTitle(portalName);
                    selectedFound = true;
                } else if (cursor.isLast() && !selectedFound && mSelectedFragmentId >= 0) {
                    mSelectedFragmentId = portalId;
                    portalItem.withSetSelected(true);
                    setTitle(portalName);
                    showToolbar();
                }

                mPortalDrawerItem.withSubItems(portalItem);
            } while (cursor.moveToNext());
        }

        // Insert control entries
        mPortalDrawerItem.withSubItems(ADD_PORTAL_DRAWER_ITEM, MANAGE_PORTAL_DRAWER_ITEM);

        // Notify about changes
        if (mPortalDrawerItem.isExpanded()) {
            mDrawer.getExpandableExtension()
                    .notifyAdapterSubItemsChanged(mDrawer.getPosition(mPortalDrawerItem), oldPortalCount);
        }

        // Set default title as title on empty cursor
        if (cursor.getCount() == 0) {
            setTitle(R.string.drawer_portal);
            showToolbar();
        }

        // Show saved fragment in UI
        showOrResetFragment(mSelectedFragmentId);

        break;
    }
    case CREDENTIAL_LOADER_ID: {
        Timber.d("Credential data loaded");

        if (mProfiles.getActiveProfile() == null)
            return;

        // Prepare result
        StringBuilder builder = new StringBuilder();
        if (cursor.moveToFirst()) {
            do {

                if (builder.length() > 0) {
                    builder.append("; ");
                }

                int rawCredit = cursor.getInt(1);
                builder.append(MenuUtils.getPriceStr(this, rawCredit));
            } while (cursor.moveToNext());
        }

        // Show result
        ((ProfileDrawerItem) mProfiles.getActiveProfile()).withEmail(builder.toString()).withNameShown(true);
        mProfiles.updateProfile(mProfiles.getActiveProfile());
        break;
    }
    case EDIT_ACTIONS_COUNT_LOADER_ID:
        Timber.i("Edit actions count loaded");
        if (cursor.moveToFirst()) {
            if (cursor.getInt(0) > 0) {
                setMenuEditUiShown(true);
            } else {
                setMenuEditUiShown(false);
            }
        }

        if (BuildConfig.DEBUG) {
            Assert.isOne(cursor.getCount());
        }
        break;
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + loader.getId());
    }
}

From source file:com.xplink.android.carchecklist.CarCheckListActivity.java

private List<Map> restoreCheckList() {
    // check getListMem

    List<Map> tmpList = null;
    SharedPreferences shared = getSharedPreferences("mysettings", Context.MODE_PRIVATE);
    String check = "empty";
    boolean stateGetList = shared.getBoolean("stateGetList", false);
    int indexList = shared.getInt("indexList", -1);

    if (stateGetList) {
        // Log.i("inCheck_satetGetList", "inCheck_stateGetList");
        DBCarCheckList dbList = new DBCarCheckList(this);
        SQLiteDatabase sqliteList = dbList.getReadableDatabase();
        String sqlList = "SELECT * FROM " + dbList.TABLE_NAME;
        Cursor cursor = sqliteList.rawQuery(sqlList, null);
        cursor.moveToFirst();//from  w  w  w .ja  v  a  2s  . c  om
        int numRow = cursor.getCount();
        String[] idList = new String[numRow];
        int i = 0;

        int id = -1;
        String username = "empty";
        String data = "empty";

        while (cursor != null) {
            idList[i] = cursor.getString(0);
            i++;
            if (cursor.isLast())
                break;
            cursor.moveToNext();
        }

        // restore from save list
        String iD = idList[indexList];
        sqlList = "SELECT * FROM " + dbList.TABLE_NAME + " WHERE id=" + iD;

        Cursor cursor2 = sqliteList.rawQuery(sqlList, null);
        cursor2.moveToFirst();
        ExpandData ex = new ExpandData(getApplicationContext());
        tmpList = ex.filterData(cursor2.getString(2));
        ex.displayMap(tmpList.get(0), tmpList.get(1));
        check = " , data : " + cursor2.getString(2);

        cursor2.close();
        sqliteList.close();
        dbList.close();

        int[] expand = ex.getPercentAllList();
        // IT'S WORK FOR TEST
        // ****************************************************************
        PercenPower = expand[0];
        PercenEngine = expand[1];
        PercenExterior = expand[2];
        PercenInterior = expand[3];
        PercenDocument = expand[4];

        /*CheckPowerTotal = shared.getInt("CheckPowerTotal", 0);
        CheckEngineTotal = shared.getInt("CheckEngineTotal", 0);
        CheckExteriorTotal = shared.getInt("CheckExteriorTotal", 0);
        CheckInteriorTotal = shared.getInt("CheckInteriorTotal", 0);
        CheckDocumentTotal = shared.getInt("CheckDocumentTotal", 0);*/

        // IT'S WORK FOR TEST
        // ****************************************************************
    } else {
        Log.i("inCheck_satetGetList", "out stateGetList");
    }
    // Log.i("stateGetList2", "stateGetList >--->>" + stateGetList + check);
    // Log.i("indexList", "getIndexList >>>>>>> " + indexList);
    if (stateGetList) {
        Editor edit = shared.edit();
        edit.clear();
        edit.commit();
        Checknumcheckbox();
        edit.putInt("checknum", Checknum);
        edit.commit();
    }
    return tmpList;
}