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.andrew.apollo.menu.PlaylistDialog.java

private String makePlaylistName() {

    String template = getString(R.string.new_playlist_name_template);
    int num = 1;/*from  w  w  w .  j  a  v  a 2s.  c  o  m*/

    String[] cols = new String[] { Audio.Playlists.NAME };
    ContentResolver resolver = getContentResolver();
    String whereclause = Audio.Playlists.NAME + " != ''";
    Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null,
            Audio.Playlists.NAME);

    if (cursor == null)
        return null;

    String suggestedname;
    suggestedname = String.format(template, num++);

    // Need to loop until we've made 1 full pass through without finding a
    // match. Looping more than once shouldn't happen very often, but will
    // happen if you have playlists named
    // "New Playlist 1"/10/2/3/4/5/6/7/8/9, where making only one pass would
    // result in "New Playlist 10" being erroneously picked for the new
    // name.
    boolean done = false;
    while (!done) {
        done = true;
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String playlistname = cursor.getString(0);
            if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
                suggestedname = String.format(template, num++);
                done = false;
            }
            cursor.moveToNext();
        }
    }
    cursor.close();
    return suggestedname;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java

private void onMarkerLoaderComplete(Cursor cursor) {
    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();/* w ww .  j  av a2  s . c o  m*/
        while (!cursor.isAfterLast()) {
            // get data
            String id = cursor.getString(MarkerQuery.MARKER_ID);
            int floor = cursor.getInt(MarkerQuery.MARKER_FLOOR);
            float lat = cursor.getFloat(MarkerQuery.MARKER_LATITUDE);
            float lon = cursor.getFloat(MarkerQuery.MARKER_LONGITUDE);
            String type = cursor.getString(MarkerQuery.MARKER_TYPE);
            String label = cursor.getString(MarkerQuery.MARKER_LABEL);
            String track = cursor.getString(MarkerQuery.MARKER_TRACK);

            BitmapDescriptor icon = null;
            if (TYPE_SESSION.equals(type)) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_session);
            } else if (TYPE_SANDBOX.equals(type)) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_sandbox);
            } else if (TYPE_LABEL.equals(type)) {
                Bitmap b = MapUtils.createTextLabel(label, mDPI);
                if (b != null) {
                    icon = BitmapDescriptorFactory.fromBitmap(b);
                }
            }

            // add marker to map
            if (icon != null) {
                Marker m = mMap.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title(id)
                        .snippet(type).icon(icon).visible(false));

                MarkerModel model = new MarkerModel(id, floor, type, label, track, m);

                mMarkersFloor.get(floor).add(m);
                mMarkers.put(id, model);
            }

            cursor.moveToNext();
        }
        // no more markers to load
        mMarkersLoaded = true;
        enableFloors();
    }

}

From source file:com.piusvelte.wapdroid.MapData.java

public void mapData() {
    mLoadingDialog = new ProgressDialog(this);
    mLoadingDialog.setTitle(R.string.loading);
    mLoadingDialog.setMessage((mPair == 0 ? Wapdroid.Ranges.NETWORK : Wapdroid.Ranges.CELL));
    mLoadingDialog.setCancelable(true);//ww w .j a v  a  2s  .c o  m
    mLoadingDialog.setOnCancelListener(this);
    mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this);
    mLoadingDialog.show();
    mThread = new Thread() {
        public void run() {
            String ssid = "", bssid = "", towers = "";
            int ctr = 0;
            List<Overlay> mapOverlays = mMView.getOverlays();
            GeoPoint point = new GeoPoint(0, 0);
            Cursor pairs = MapData.this.getContentResolver().query(Wapdroid.Ranges.CONTENT_URI,
                    new String[] { Wapdroid.Ranges._ID, Wapdroid.Ranges.SSID, Wapdroid.Ranges.BSSID,
                            Wapdroid.Ranges.CID, Wapdroid.Ranges.LAC, Wapdroid.Ranges.RSSI_MIN,
                            Wapdroid.Ranges.RSSI_MAX },
                    mPair == 0 ? Wapdroid.Ranges.NETWORK + "=" + mNetwork : Wapdroid.Ranges._ID + "=" + mPair,
                    null, null);
            int ct = pairs.getCount();
            if (pairs.moveToFirst()) {
                WapdroidItemizedOverlay pinOverlays = new WapdroidItemizedOverlay((MapData) mContext, ct);
                while (!interrupted() && !pairs.isAfterLast()) {
                    ctr++;
                    int cid = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.CID)),
                            lac = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.LAC)),
                            rssi_min = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.RSSI_MIN)),
                            rssi_max = pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges.RSSI_MAX)),
                            rssi_avg = Math.round((rssi_min + rssi_max) / 2),
                            rssi_range = Math.abs(rssi_min) - Math.abs(rssi_max);
                    mMsg = string_cellWarning + Wapdroid.Ranges.CELL + " " + Integer.toString(ctr) + " of "
                            + Integer.toString(ct);
                    mHandler.post(mUpdtDialog);
                    String tower = "{" + String.format(SAddInt, cell_id, cid) + ","
                            + String.format(SAddInt, location_area_code, lac) + ","
                            + String.format(SAddInt, mcc, mMCC) + "," + String.format(SAddInt, mnc, mMNC);
                    if (rssi_avg != Wapdroid.UNKNOWN_RSSI)
                        tower += "," + String.format(SAddInt, signal_strength, rssi_avg);
                    tower += "}";
                    if (ssid == "")
                        ssid = pairs.getString(pairs.getColumnIndex(Wapdroid.Ranges.SSID));
                    if (bssid == "")
                        bssid = pairs.getString(pairs.getColumnIndex(Wapdroid.Ranges.BSSID));
                    if (towers != "")
                        towers += ",";
                    towers += tower;
                    point = getGeoPoint(bldRequest(tower, bssid));
                    pinOverlays.addOverlay(new WapdroidOverlayItem(point, Wapdroid.Ranges.CELL,
                            string_cid + Integer.toString(cid) + string_linefeed + string_lac
                                    + Integer.toString(lac) + string_linefeed + string_range
                                    + Integer.toString(rssi_min) + string_colon + Integer.toString(rssi_max),
                            mNetwork, pairs.getInt(pairs.getColumnIndex(Wapdroid.Ranges._ID)), rssi_avg,
                            rssi_range));
                    pairs.moveToNext();
                }
                if (mPair == 0) {
                    mMsg = Wapdroid.Ranges.NETWORK + ": " + ssid;
                    mHandler.post(mUpdtDialog);
                    point = getGeoPoint(bldRequest(towers, bssid));
                    Location location = new Location("");
                    location.setLatitude(point.getLatitudeE6() / 1e6);
                    location.setLongitude(point.getLongitudeE6() / 1e6);
                    pinOverlays.addOverlay(
                            new WapdroidOverlayItem(point, Wapdroid.Ranges.NETWORK, ssid, mNetwork),
                            drawable_network);
                    pinOverlays.setDistances(location);
                }
                mapOverlays.add(pinOverlays);
                mMController.setCenter(point);
            }
            pairs.close();
            mLoadingDialog.dismiss();
            interrupt();
        }
    };
    mThread.start();
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java

private void onTracksLoaderComplete(Cursor cursor) {
    if (cursor != null) {
        mTracks = new HashMap<String, TrackModel>();
        cursor.moveToFirst();//from  w w  w .ja va 2s . com
        while (!cursor.isAfterLast()) {
            final String name = cursor.getString(TracksQuery.TRACK_NAME);
            final String id = cursor.getString(TracksQuery.TRACK_ID);
            final int color = cursor.getInt(TracksQuery.TRACK_COLOR);

            mTracks.put(id, new TrackModel(id, name, color));
            cursor.moveToNext();
        }
        mTracksLoaded = true;
        enableFloors();
    }

}

From source file:org.musicmod.android.dialog.PlaylistDialog.java

private String makePlaylistName() {

    String template = getString(R.string.new_playlist_name_template);
    int num = 1;/*from w w  w. j  av  a 2 s  .  c om*/

    String[] cols = new String[] { MediaStore.Audio.Playlists.NAME };
    ContentResolver resolver = getContentResolver();
    String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
    Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null,
            MediaStore.Audio.Playlists.NAME);

    if (cursor == null) {
        return null;
    }

    String suggestedname;
    suggestedname = String.format(template, num++);

    // Need to loop until we've made 1 full pass through without finding a
    // match. Looping more than once shouldn't happen very often, but will
    // happen if you have playlists named
    // "New Playlist 1"/10/2/3/4/5/6/7/8/9, where making only one pass would
    // result in "New Playlist 10" being erroneously picked for the new
    // name.
    boolean done = false;
    while (!done) {
        done = true;
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            String playlistname = cursor.getString(0);
            if (playlistname.compareToIgnoreCase(suggestedname) == 0) {
                suggestedname = String.format(template, num++);
                done = false;
            }
            cursor.moveToNext();
        }
    }
    cursor.close();
    return suggestedname;
}

From source file:com.kaku.weac.fragment.LocalMusicFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case LOADER_ID:
        // ??????
        String ringName1;/*from  w  ww  .j  a  v  a2 s  . co m*/
        if (RingSelectFragment.sRingName != null) {
            ringName1 = RingSelectFragment.sRingName;
        } else {
            SharedPreferences share = getActivity().getSharedPreferences(WeacConstants.EXTRA_WEAC_SHARE,
                    Activity.MODE_PRIVATE);
            // ??????
            ringName1 = share.getString(WeacConstants.RING_NAME, "");
        }
        // ??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, ringName1);
        setListAdapter(mLocalMusicAdapter);
        setSelection(mPosition);
        break;
    }
}

From source file:net.kourlas.voipms_sms.Database.java

/**
 * Gets all of the messages in the database except for deleted messages.
 *
 * @return All of the messages in the database except for deleted messages.
 *//*from ww  w  . j  av a  2 s . c o  m*/
public synchronized Message[] getUndeletedMessages(String did) {
    List<Message> messages = new ArrayList<>();

    Cursor cursor = database.query(TABLE_MESSAGE, columns,
            COLUMN_DID + "=" + did + " AND " + COLUMN_DELETED + "=" + "0", null, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Message message = new Message(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATABASE_ID)),
                cursor.isNull(cursor.getColumnIndexOrThrow(COLUMN_VOIP_ID)) ? null
                        : cursor.getLong(cursor.getColumnIndex(COLUMN_VOIP_ID)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATE)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_TYPE)),
                cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_DID)),
                cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CONTACT)),
                cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MESSAGE)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_UNREAD)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELETED)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERED)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERY_IN_PROGRESS)));
        messages.add(message);
        cursor.moveToNext();
    }
    cursor.close();

    Collections.sort(messages);

    Message[] messageArray = new Message[messages.size()];
    return messages.toArray(messageArray);
}

From source file:net.kourlas.voipms_sms.Database.java

/**
 * Gets all of the deleted messages in the database.
 *
 * @return All of the deleted messages in the database.
 *//*from  ww w .  j a  va 2  s  .  c o m*/
public synchronized Message[] getDeletedMessages(String did) {
    List<Message> messages = new ArrayList<>();

    Cursor cursor = database.query(TABLE_MESSAGE, columns,
            COLUMN_DID + "=" + did + " AND " + COLUMN_DELETED + "=" + "1", null, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Message message = new Message(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATABASE_ID)),
                cursor.isNull(cursor.getColumnIndexOrThrow(COLUMN_VOIP_ID)) ? null
                        : cursor.getLong(cursor.getColumnIndex(COLUMN_VOIP_ID)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATE)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_TYPE)),
                cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_DID)),
                cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CONTACT)),
                cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MESSAGE)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_UNREAD)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELETED)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERED)),
                cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERY_IN_PROGRESS)));
        messages.add(message);
        cursor.moveToNext();
    }
    cursor.close();

    Collections.sort(messages);

    Message[] messageArray = new Message[messages.size()];
    return messages.toArray(messageArray);
}

From source file:net.potterpcs.recipebook.RecipeData.java

public String[] getRecipeTagStrings(long rid) {
    Cursor c = getRecipeTags(rid);
    String[] tags = new String[c.getCount()];

    c.moveToFirst();/*  www  .j  av a2  s  .co  m*/
    while (!c.isAfterLast()) {
        tags[c.getPosition()] = c.getString(c.getColumnIndex(TT_TAG));
        c.moveToNext();
    }

    c.close();
    return tags;
}

From source file:net.potterpcs.recipebook.RecipeData.java

public String[] getRecipeIngredientStrings(long rid) {
    Cursor c = getRecipeIngredients(rid);
    String[] ings = new String[c.getCount()];

    c.moveToFirst();//  w ww  .  j a v  a 2s.co m
    while (!c.isAfterLast()) {
        ings[c.getPosition()] = c.getString(c.getColumnIndex(IT_NAME));
        c.moveToNext();
    }

    c.close();
    return ings;
}