Example usage for android.database Cursor moveToNext

List of usage examples for android.database Cursor moveToNext

Introduction

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

Prototype

boolean moveToNext();

Source Link

Document

Move the cursor to the next row.

Usage

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java

/**
 * Gets a TransferObserver instance to track the record with the given id.
 *
 * @param id A transfer id./*from   ww w . j  a  v a 2 s .c  o m*/
 * @return The TransferObserver instance which is observing the record.
 */
public TransferObserver getTransferById(int id) {
    Cursor c = null;
    try {
        c = dbUtil.queryTransferById(id);
        if (c.moveToNext()) {
            final TransferObserver to = new TransferObserver(id, dbUtil);
            to.updateFromDB(c);
            return to;
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return null;
}

From source file:com.parking.billing.ParkingPayment.java

/**
 * Reads the set of purchased items from the database in a background thread
 * and then adds those items to the set of owned items in the main UI
 * thread./*from  ww w .  jav a2s  . c o  m*/
 */
private void doInitializeOwnedItems() {
    Cursor cursor = mPurchaseDatabase.queryAllPurchasedItems();
    if (cursor == null) {
        return;
    }

    final Set<String> ownedItems = new HashSet<String>();
    try {
        int productIdCol = cursor.getColumnIndexOrThrow(PurchaseDatabase.PURCHASED_PRODUCT_ID_COL);
        while (cursor.moveToNext()) {
            String productId = cursor.getString(productIdCol);
            ownedItems.add(productId);
        }
    } finally {
        cursor.close();
    }

    // We will add the set of owned items in a new Runnable that runs on
    // the UI thread so that we don't need to synchronize access to
    // mOwnedItems.
    mHandler.post(new Runnable() {
        public void run() {
            mOwnedItems.addAll(ownedItems);
            mCatalogAdapter.setOwnedItems(mOwnedItems);
        }
    });
}

From source file:com.intel.xdk.contacts.Contacts.java

public String JSONValueForPerson(String idlk) {
    ContentResolver cr = activity.getContentResolver();
    //PROCESS NAME ELEMENTS FOR CURRENT CONTACT ID
    String firstName = "", lastName = "", compositeName = "", id = "";
    String nameWhere = ContactsContract.Data.LOOKUP_KEY + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
    String[] params = new String[] { idlk, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE };
    Cursor nameCur = cr.query(ContactsContract.Data.CONTENT_URI, null, nameWhere, params, null);
    if (nameCur.getCount() > 0) {
        nameCur.moveToFirst();//from w w w .  j  a v a  2  s . c  o  m
        id = nameCur.getString(nameCur.getColumnIndex(ContactsContract.Data.CONTACT_ID));

        firstName = nameCur
                .getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
        lastName = nameCur
                .getString(nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
        compositeName = nameCur.getString(
                nameCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME));

        firstName = (firstName == null) ? "" : escapeStuff(firstName);
        lastName = (lastName == null) ? "" : escapeStuff(lastName);
        compositeName = (compositeName == null) ? "" : escapeStuff(compositeName);
    }

    //PROCESS EMAIL ADDRESES FOR CURRENT CONTACT ID
    Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
            ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[] { id }, null);
    String emailAddresses = "[]";
    if (emailCur.getCount() > 0) {
        emailAddresses = "[";
        while (emailCur.moveToNext()) {
            String email = emailCur
                    .getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
            email = escapeStuff(email);
            //String emailType = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 

            emailAddresses += "'" + email + "', ";

        }
        emailAddresses += "]";
    }
    emailCur.close();

    //PROCESS PHONE NUMBERS FOR CURRENT CONTACT ID
    Cursor phoneCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);

    String phoneNumbers = "[]";
    if (phoneCur.getCount() > 0) {
        phoneNumbers = "[";
        while (phoneCur.moveToNext()) {
            String phoneNum = phoneCur
                    .getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            phoneNum = escapeStuff(phoneNum);
            phoneNumbers += "'" + phoneNum + "', ";
        }
        phoneNumbers += "]";
    }
    phoneCur.close();

    //PROCESS STREET ADDRESSES FOR CURRENT CONTACT ID
    String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
    String[] addrWhereParams = new String[] { id,
            ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE };
    Cursor addressCur = cr.query(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI, null, addrWhere,
            addrWhereParams, null);

    String streetAddresses = "[]";
    if (addressCur.getCount() > 0) {
        streetAddresses = "[";
        while (addressCur.moveToNext()) {

            String street = addressCur.getString(
                    addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET));
            String city = addressCur.getString(
                    addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY));
            String state = addressCur.getString(
                    addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION));
            String zip = addressCur.getString(
                    addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE));
            String country = addressCur.getString(
                    addressCur.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY));

            street = escapeStuff(street);
            city = escapeStuff(city);
            state = escapeStuff(state);
            zip = escapeStuff(zip);
            country = escapeStuff(country);

            String addressstr = String.format(
                    "{ street:'%s', city:'%s', state:'%s', zip:'%s', country:'%s' }, ", street, city, state,
                    zip, country);
            streetAddresses += addressstr;

        }
        streetAddresses += "]";
    }
    addressCur.close();

    String jsPerson = String.format(
            "{ id:'%s', name:'%s', first:'%s', last:'%s', phones:%s, emails:%s, addresses:%s }, ", idlk,
            compositeName, firstName, lastName, phoneNumbers, emailAddresses, streetAddresses);
    return jsPerson.replaceAll("\\r\\n|\\r|\\n", "\\\\n");

}

From source file:com.navjagpal.fileshare.WebServer.java

private String getFolderListing() {
    /* Get list of folders */
    Cursor c = mContext.getContentResolver().query(FileSharingProvider.Folders.CONTENT_URI, null, null, null,
            null);/* w  ww.  j  av  a2s  .c o m*/
    int nameIndex = c.getColumnIndexOrThrow(FileSharingProvider.Folders.Columns.DISPLAY_NAME);
    int idIndex = c.getColumnIndexOrThrow(FileSharingProvider.Folders.Columns._ID);
    String s = "";
    while (c.moveToNext()) {
        String name = c.getString(nameIndex);
        int id = c.getInt(idIndex);
        s += folderToLink(name, id) + "<br/>";
    }
    c.close();
    return s;
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void update_agent_autocomplete(int id) {
    ArrayAdapter<String> agents = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
    Cursor c = mDbHelper.fetch_agents();
    if (c.moveToFirst())
        do {/*from   w ww .  ja  va  2s.co  m*/
            agents.add(c.getString(c.getColumnIndex(DbAdapter.KEY_AGENT)));
        } while (c.moveToNext());
    c.close();
    AutoCompleteTextView agents_entry = (AutoCompleteTextView) findViewById(id);
    agents_entry.setThreshold(1);
    agents_entry.setAdapter(agents);
}

From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java

void populateReminders(Event e) throws RemoteException {
    // reminders// w  ww  . ja v  a  2 s .c o  m
    Uri remindersUri = Reminders.CONTENT_URI.buildUpon()
            .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
    @Cleanup
    Cursor c = providerClient.query(remindersUri, new String[] { /* 0 */ Reminders.MINUTES, Reminders.METHOD },
            Reminders.EVENT_ID + "=?", new String[] { String.valueOf(e.getLocalID()) }, null);
    while (c != null && c.moveToNext()) {
        VAlarm alarm = new VAlarm(new Dur(0, 0, -c.getInt(0), 0));

        PropertyList props = alarm.getProperties();
        switch (c.getInt(1)) {
        /*case Reminders.METHOD_EMAIL:
           props.add(Action.EMAIL);
           break;*/
        default:
            props.add(Action.DISPLAY);
            props.add(new Description(e.getSummary()));
        }
        e.addAlarm(alarm);
    }
}

From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java

private void update_station_autocomplete(int id) {
    ArrayAdapter<String> stations = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
    Cursor c = mDbHelper.fetch_stations();
    if (c.moveToFirst())
        do {//from  w  w w. ja v a  2s .co m
            stations.add(c.getString(c.getColumnIndex(DbAdapter.KEY_STN)));
        } while (c.moveToNext());
    c.close();
    AutoCompleteTextView stations_entry = (AutoCompleteTextView) findViewById(id);
    stations_entry.setThreshold(1);
    stations_entry.setAdapter(stations);
}

From source file:heartware.com.heartware_master.DBAdapter.java

public ArrayList<HashMap<String, String>> getAllProfiles() {
    ArrayList<HashMap<String, String>> profileArrayList;
    profileArrayList = new ArrayList<HashMap<String, String>>();
    String selectQuery = "SELECT * FROM " + PROFILES_TABLE + " ORDER BY " + USERNAME + " ASC";
    SQLiteDatabase database = this.getWritableDatabase();
    Cursor cursor = database.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {//from  w  ww . j  a v a  2 s .co m
            HashMap<String, String> profileMap = new HashMap<String, String>();
            profileMap.put(PROFILE_ID, cursor.getString(0));
            profileMap.put(USERNAME, cursor.getString(1));
            profileMap.put(PASSWORD, cursor.getString(2));
            profileMap.put(DIFFICULTY, cursor.getString(3));
            profileMap.put(DISABILITY, cursor.getString(4));
            profileArrayList.add(profileMap);
        } while (cursor.moveToNext());
    }

    return profileArrayList;
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java

/**
 * Pauses all transfers which have the given type.
 *
 * @param type The type of transfers//from   www .  j  ava 2 s  .  c om
 */
public void pauseAllWithType(TransferType type) {
    Cursor c = null;
    try {
        c = dbUtil.queryAllTransfersWithType(type);
        while (c.moveToNext()) {
            final int id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID));
            pause(id);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility.java

/**
 * Sets all transfers which have the given type to be canceled. Note the
 * TransferState must be TransferState.CANCELED before the transfer is
 * guaranteed to have stopped, and can be safely deleted
 *
 * @param type The type of transfers/* w  ww . j av  a  2s  .  c om*/
 */
public void cancelAllWithType(TransferType type) {
    Cursor c = null;
    try {
        c = dbUtil.queryAllTransfersWithType(type);
        while (c.moveToNext()) {
            final int id = c.getInt(c.getColumnIndexOrThrow(TransferTable.COLUMN_ID));
            cancel(id);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
}