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:com.granita.tasks.EditTaskFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    mTaskListAdapter.changeCursor(cursor);
    if (cursor != null) {
        // set the list that was used the last time the user created an event
        if (mSelectedList != -1) {
            // iterate over all lists and select the one that matches the given id
            cursor.moveToFirst();//from   w w  w .j  a  va  2  s .  c  om
            while (!cursor.isAfterLast()) {
                Long listId = cursor.getLong(TASK_LIST_PROJECTION_VALUES.id);
                if (listId != null && listId == mSelectedList) {
                    mListSpinner.setSelection(cursor.getPosition());
                    break;
                }
                cursor.moveToNext();
            }
        }
    }
}

From source file:cz.tsystems.portablecheckin.MainActivity.java

private void populateView() throws ParseException {

    app.dismisProgressDialog();/*from ww  w.  j av  a  2 s.c o  m*/
    populateTextsAndRbtn(values1);
    populateTextsAndRbtn(values2);
    DMCheckin checkinData = app.getCheckin();

    //      getActivity().setTitle(checkinData.vehicle_description);

    if (checkinData.check_scenario_id <= 0)
        checkinData.check_scenario_id = app.getSelectedBrand().check_scenario_id_def;

    app.setSelectedScenar(checkinData.check_scenario_id);
    app.loadUnits();

    if (checkinData.fuel_id <= 0)
        checkinData.fuel_id = 0;

    Cursor cursor = app.getPaliva();
    cursor.moveToFirst();
    final int searchedId = cursor.getColumnIndex("FUEL_ID");
    int pos = -1;
    while (!cursor.isAfterLast()) {
        pos++;
        if (cursor.getInt(searchedId) == checkinData.fuel_id)
            break;
        cursor.moveToNext();
    }
    spTypPaliva.setSelection(pos, true);

    cursor = null;
    cursor = app.getScenare(checkinData.brand_id);
    final int checkScenarioIdIndex = cursor.getColumnIndex("CHECK_SCENARIO_ID");
    final int checkScenarioDefTextIndex = cursor.getColumnIndex("TEXT");
    final int scenarId = app.getSelectedScenar().check_scenario_id;
    pos = -1;
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        pos++;
        Log.v(TAG, String.valueOf(scenarId) + " == " + cursor.getString(checkScenarioIdIndex) + ", "
                + cursor.getString(checkScenarioDefTextIndex));
        if (cursor.getInt(checkScenarioIdIndex) == scenarId)
            break;
        cursor.moveToNext();
    }
    spScenare.setSelection(pos, true);

    app.loadSilhouette();
    ((FragmentPagerActivity) getActivity()).updateData();

    com.gc.materialdesign.views.Slider slaider = (com.gc.materialdesign.views.Slider) values1
            .findViewById(R.id.slaiderStavPaliva);
    slaider.setValue(checkinData.fuel_level);

    slaider = (com.gc.materialdesign.views.Slider) values2.findViewById(R.id.slaiderInterier);
    slaider.setValue(checkinData.interior_state);

    slaider = (com.gc.materialdesign.views.Slider) values2.findViewById(R.id.slaiderStavOleje);
    slaider.setValue(checkinData.oil_level);

    txtVIN.setEnabled((checkinData.vehicle_id == null));
    txtRZV.setEnabled((checkinData.vehicle_id == null));

    setEnableButton(fbtPZ, (PortableCheckin.plannedActivitiesList != null
            && PortableCheckin.plannedActivitiesList.size() > 0));
    setEnableButton(fbtMajak,
            (PortableCheckin.odlozenePolozky != null && PortableCheckin.odlozenePolozky.size() > 0));
    setEnableButton(fbtMegafon, (PortableCheckin.sda != null && PortableCheckin.sda.size() > 0));
}

From source file:com.spoiledmilk.ibikecph.util.DB.java

public SearchListItem getSearchHistoryByName(String name) {

    SearchListItem ret = null;/*from  w w w  . java 2 s  . c  o  m*/

    SQLiteDatabase db = getReadableDatabase();
    if (db == null)
        return null;

    String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_START_DATE, KEY_END_DATE, KEY_SOURCE, KEY_SUBSOURCE,
            KEY_LAT, KEY_LONG };

    Cursor cursor = db.query(TABLE_SEARCH_HISTORY, columns, KEY_NAME + " = ? ", new String[] { name.trim() },
            null, null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
        while (cursor != null && !cursor.isAfterLast()) {
            int colId = cursor.getColumnIndex(KEY_ID);
            int colName = cursor.getColumnIndex(KEY_NAME);
            int colAddress = cursor.getColumnIndex(KEY_ADDRESS);
            int colStartDate = cursor.getColumnIndex(KEY_START_DATE);
            int colEndDate = cursor.getColumnIndex(KEY_END_DATE);
            int colSource = cursor.getColumnIndex(KEY_SOURCE);
            int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE);
            int colLat = cursor.getColumnIndex(KEY_LAT);
            int colLong = cursor.getColumnIndex(KEY_LONG);

            HistoryData hd = new HistoryData(cursor.getInt(colId), cursor.getString(colName),
                    cursor.getString(colAddress), cursor.getString(colStartDate), cursor.getString(colEndDate),
                    cursor.getString(colSource), cursor.getString(colSubSource), cursor.getDouble(colLat),
                    cursor.getDouble(colLong));
            if (hd.getName() != null && !hd.getName().trim().equals("")) {
                ret = hd;
            }
            break;
        }
    }

    if (cursor != null)
        cursor.close();

    db.close();

    return ret;
}

From source file:com.spoiledmilk.ibikecph.util.DB.java

public ArrayList<SearchListItem> getFavoritesForString(String srchString) {
    ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>();

    SQLiteDatabase db = getReadableDatabase();
    if (db == null)
        return null;

    String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG,
            KEY_API_ID };//  ww  w .  ja  v a  2s.c  om

    Cursor cursor = db.query(TABLE_FAVORITES, columns, KEY_NAME + " LIKE ? ",
            new String[] { "%" + srchString + "%" }, null, null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
        while (cursor != null && !cursor.isAfterLast()) {
            int colId = cursor.getColumnIndex(KEY_ID);
            int colName = cursor.getColumnIndex(KEY_NAME);
            int colAddress = cursor.getColumnIndex(KEY_ADDRESS);
            int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE);
            int colLat = cursor.getColumnIndex(KEY_LAT);
            int colLong = cursor.getColumnIndex(KEY_LONG);
            int colApiId = cursor.getColumnIndex(KEY_API_ID);

            FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName),
                    cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat),
                    cursor.getDouble(colLong), cursor.getInt(colApiId));

            ret.add((SearchListItem) fd);
            cursor.moveToNext();
        }
    }

    if (cursor != null)
        cursor.close();

    db.close();

    return ret;
}

From source file:com.mikifus.padland.PadListActivity.java

/**
 * Gets an adapter for the expandableListView with the contents from the database
 *
 * @return/*from ww  w  .jav a2s. c  o  m*/
 */
//    private void setAdapter()
//    {
////        ArrayList<HashMap<String, ArrayList>> group_data = getGroupsForAdapter();
//        HashMap<Long, ArrayList<String>> padlist_data = _getPadListData();
//
//        adapter = new PadListAdapter(this);
//
//        // Bind to adapter.
//        expandableListView.setAdapter(adapter);
//
//        // Expand all groups by default
//        for(int i=0; i < adapter.getGroupCount(); i++) {
//            expandableListView.expandGroup(i);
//        }
//    }

private HashMap<Long, ArrayList<String>> _getPadListData() {
    Uri padlist_uri = Uri.parse(getString(R.string.request_padlist));
    Cursor cursor = getContentResolver().query(padlist_uri,
            new String[] { PadContentProvider._ID, PadContentProvider.NAME, PadContentProvider.URL }, null,
            null, PadContentProvider.LAST_USED_DATE + " ASC");

    HashMap<Long, ArrayList<String>> result = new HashMap<>();

    if (cursor == null || cursor.getCount() == 0) {
        return result;
    }

    HashMap<Long, ArrayList<String>> pad_data = new HashMap<>();

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        long id = cursor.getLong(0);
        String name = cursor.getString(1);
        String url = cursor.getString(2);

        ArrayList<String> pad_strings = new ArrayList<String>();
        pad_strings.add(name);
        pad_strings.add(url);

        pad_data.put(id, pad_strings);

        // do something
        cursor.moveToNext();
    }
    cursor.close();

    return pad_data;
}

From source file:cz.tsystems.portablecheckin.MainActivity.java

private void setScenareSpinner() {
    Cursor cursor = app.getScenare(app.getCheckin().brand_id);
    final int columnIndex = cursor.getColumnIndex("CHECK_SCENARIO_ID");
    final int scenarId = app.getSelectedScenar().check_scenario_id;
    int pos = -1;
    while (!cursor.isAfterLast()) {
        pos++;/*from  w w w  . j av  a  2 s  . co  m*/
        if (cursor.getInt(columnIndex) == scenarId)
            break;
        cursor.moveToNext();
    }

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(),
            android.R.layout.simple_spinner_dropdown_item, cursor, new String[] { "TEXT" },
            new int[] { android.R.id.text1 }, 0);
    spScenare.setAdapter(adapter);
    //      spScenare.setSelection(pos, true);
}

From source file:org.openbmap.soapclient.GpxExporter.java

/**
 * Iterates on track points and write them.
 * @param trackName Name of the track (metadata).
 * @param bw Writer to the target file.//from   w  w w  . ja v a2  s .com
 * @param c Cursor to track points.
 * @throws IOException
 */
private void writeTrackpoints(final int session, final String trackName, final BufferedWriter bw)
        throws IOException {
    Log.i(TAG, "Writing trackpoints");

    Cursor c = mDbHelper.getReadableDatabase().rawQuery(TRACKPOINT_SQL_QUERY1,
            new String[] { String.valueOf(mSession), String.valueOf(0) });

    final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE);
    final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE);
    final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE);
    final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP);

    bw.write("\t<trk>");
    bw.write("\t\t<name>");
    bw.write(trackName);
    bw.write("</name>\n");
    bw.write("\t\t<trkseg>\n");

    long outer = 0;
    while (!c.isAfterLast()) {
        c.moveToFirst();
        //StringBuffer out = new StringBuffer(32 * 1024);
        while (!c.isAfterLast()) {
            bw.write("\t\t\t<trkpt lat=\"");
            bw.write(String.valueOf(c.getDouble(colLatitude)));
            bw.write("\" ");
            bw.write("lon=\"");
            bw.write(String.valueOf(c.getDouble(colLongitude)));
            bw.write("\">");
            bw.write("<ele>");
            bw.write(String.valueOf(c.getDouble(colAltitude)));
            bw.write("</ele>");
            bw.write("<time>");
            // time stamp conversion to ISO 8601
            bw.write(getGpxDate(c.getLong(colTimestamp)));
            bw.write("</time>");
            bw.write("</trkpt>\n");

            c.moveToNext();
        }
        //bw.write(out.toString());
        //out = null;

        // fetch next CURSOR_SIZE records
        outer += CURSOR_SIZE;
        c.close();
        c = mDbHelper.getReadableDatabase().rawQuery(TRACKPOINT_SQL_QUERY1,
                new String[] { String.valueOf(mSession), String.valueOf(outer) });
    }
    c.close();

    bw.write("\t\t</trkseg>\n");
    bw.write("\t</trk>\n");
    System.gc();
}

From source file:org.ale.scanner.zotero.MainActivity.java

public void loadGroups() {
    if (mAccountAccess.getGroupCount() == 0 && mAccountAccess.canWriteLibrary()) {
        mGroups = new SparseArray<PString>();
        mGroups.put(Group.GROUP_LIBRARY, new PString(getString(R.string.my_library)));
        return;/*from w  ww .  jav a 2  s  . c o m*/
    }
    // Check that we have all the group titles
    new Thread(new Runnable() {
        public void run() {
            final SparseArray<PString> newGroupList = new SparseArray<PString>();
            Set<Integer> groups = mAccountAccess.getGroupIds();
            if (mAccountAccess.canWriteLibrary()) {
                newGroupList.put(Group.GROUP_LIBRARY, new PString(getString(R.string.my_library)));
            }
            String[] selection = new String[] { TextUtils.join(",", groups) };
            Cursor c = getContentResolver().query(Database.GROUP_URI,
                    new String[] { Group._ID, Group.COL_TITLE }, Group._ID + " IN (?)", selection, null);

            // Figure out which groups we don't have
            c.moveToFirst();
            while (!c.isAfterLast()) {
                int haveGroupId = c.getInt(0);
                groups.remove(haveGroupId);
                newGroupList.put(haveGroupId, new PString(c.getString(1)));
                c.moveToNext();
            }
            c.close();
            // Update the group list
            mUIThreadHandler.post(new Runnable() {
                public void run() {
                    mGroups = newGroupList;
                }
            });
            // If we have any unknown groups, do a group lookup.
            if (groups.size() > 0) {
                // Make new database entries for new groups. Mapping each
                // id to "<Group ID>" temporarily.
                ContentValues[] values = new ContentValues[groups.size()];
                int i = 0;
                for (Integer gid : groups) {
                    values[i] = new ContentValues();
                    values[i].put(Group._ID, gid);
                    values[i].put(Group.COL_TITLE, "<" + gid + ">");
                    i++;
                }
                getContentResolver().bulkInsert(Database.GROUP_URI, values);
                mZAPI.getGroups();
            }
        }
    }).start();
}

From source file:com.sferadev.etic.tasks.DownloadTasksTask.java

private void updateTaskStatusToServer(FileDbAdapter fda, String source, String username, String password,
        String serverUrl) throws Exception {

    Log.i("updateTaskStatusToServer", "Enter");
    Cursor taskListCursor = fda.fetchTasksForSource(source, false);
    taskListCursor.moveToFirst();// ww  w.j av  a  2 s.  c o  m
    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse getResponse = null;

    // Add credentials
    if (username != null && password != null) {
        client.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null),
                new UsernamePasswordCredentials(username, password));
    }

    while (!taskListCursor.isAfterLast()) {

        if (isCancelled()) {
            return;
        }
        ; // Return if the user cancels

        String newStatus = taskListCursor.getString(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_STATUS));
        String syncStatus = taskListCursor
                .getString(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_IS_SYNC));
        long aid = taskListCursor.getLong(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ASSIGNMENTID));
        long tid = taskListCursor.getLong(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ID));

        Log.i("updateTaskStatusToServer",
                "aId:" + aid + " -- status:" + newStatus + " -- syncStatus:" + syncStatus);
        // Call the update service
        if (newStatus != null && syncStatus.equals(FileDbAdapter.STATUS_SYNC_NO)) {
            Log.i(getClass().getSimpleName(), "Updating server with status of " + aid + " to " + newStatus);
            Assignment a = new Assignment();
            a.assignment_id = (int) aid;
            a.assignment_status = newStatus;

            // Call the service
            String taskURL = serverUrl + "/surveyKPI/myassignments/" + aid;
            HttpPost postRequest = new HttpPost(taskURL);

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("assignInput", "{assignment_status: " + newStatus + "}"));

            postRequest.setEntity(new UrlEncodedFormEntity(postParameters));
            getResponse = client.execute(postRequest);

            int statusCode = getResponse.getStatusLine().getStatusCode();

            if (statusCode != HttpStatus.SC_OK) {
                Log.w(getClass().getSimpleName(), "Error:" + statusCode + " for URL " + taskURL);
            } else {
                Log.w("updateTaskStatusToServer", "Status updated");
                fda.setTaskSynchronized(tid); // Mark the task status as synchronised
            }
        }

        taskListCursor.moveToNext();
    }
    taskListCursor.close();

}

From source file:de.stadtrallye.rallyesoft.model.chat.Chatroom.java

@Override
public List<ChatEntry> getUnreadEntries() {
    Cursor cursor = getChatCursor();

    CursorConverters.ChatCursorIds c = CursorConverters.ChatCursorIds.read(cursor);

    stateLock.readLock().lock();//from ww w. j  a  v  a 2  s.  com
    try {
        CursorConverters.moveCursorToId(cursor, c.id, lastReadID);
    } finally {
        stateLock.readLock().unlock();
    }

    List<ChatEntry> res = new ArrayList<>();

    cursor.moveToNext();
    while (!cursor.isAfterLast()) {
        res.add(CursorConverters.getChatEntry(cursor, c));
        cursor.moveToNext();
    }
    return res;
}