Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

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

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:com.granita.icloudcalsync.resource.LocalCalendar.java

public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient)
        throws RemoteException {
    @Cleanup
    Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME },
            Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);

    LinkedList<LocalCalendar> calendars = new LinkedList<>();
    while (cursor != null && cursor.moveToNext())
        calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1)));
    return calendars.toArray(new LocalCalendar[0]);
}

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

public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient)
        throws RemoteException {
    @Cleanup
    Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME },
            Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null);

    LinkedList<LocalCalendar> calendars = new LinkedList<>();
    while (cursor != null && cursor.moveToNext())
        calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1)));
    return calendars.toArray(new LocalCalendar[calendars.size()]);
}

From source file:Main.java

/**
 * Retourner la liste des calendriers/*from   w w w  . j a v a2 s.  c o  m*/
 * 
 * @return Liste des calendriers
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static Map<Integer, String> getCalendars(ContentResolver contentResolver) {
    Map<Integer, String> calendars = new HashMap<Integer, String>();
    String[] projection;
    Uri calendarUri;
    Cursor cursor;
    String accessLevelCol;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        calendarUri = CalendarContract.Calendars.CONTENT_URI;
        projection = new String[] { CalendarContract.Calendars._ID,
                CalendarContract.Calendars.CALENDAR_DISPLAY_NAME };
        accessLevelCol = CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        calendarUri = Uri.parse("content://com.android.calendar/calendars");
        projection = new String[] { "_id", "displayname" };
        accessLevelCol = "ACCESS_LEVEL";
    } else {
        calendarUri = Uri.parse("content://calendar/calendars");
        projection = new String[] { "_id", "displayname" };
        accessLevelCol = "ACCESS_LEVEL";
    }

    cursor = contentResolver.query(calendarUri, projection, accessLevelCol + "=700", null, null);

    if (cursor != null && cursor.moveToFirst()) {
        while (cursor.isAfterLast() == false) {
            calendars.put(cursor.getInt(0), cursor.getString(1));
            cursor.moveToNext();
        }
        cursor.close();
    }

    return calendars;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void expireReadMessages(Context context, boolean expireAll, long expireTime) {

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    // Get all the expired messages so we can delete bodies and attachments
    long currentTime = System.currentTimeMillis();
    String q = null;//from ww w  . java  2 s .com

    if (expireAll) {
        q = "SELECT _id, subscribed_group_id, has_attachments, attachments_fnames " + "FROM headers "
                + "WHERE read=1 AND catched=1";
    } else {
        q = "SELECT _id, subscribed_group_id, has_attachments, attachments_fnames " + "FROM headers "
                + "WHERE read=1 AND catched=1 AND read_unixdate < " + currentTime + " - " + expireTime;
    }

    Cursor c = dbwrite.rawQuery(q, null);

    int count = c.getCount();
    c.moveToFirst();
    String groupname;

    for (int i = 0; i < count; i++) {

        groupname = getGroupNameFromId(c.getInt(1) /*subscribed_group_id*/, context);
        FSUtils.deleteCacheMessage(c.getInt(0)/* _id */, groupname);

        if (c.getInt(2)/*has_attach*/ == 1) {
            FSUtils.deleteAttachments(c.getString(3) /*attachments_fnames*/, groupname);
        }

        c.moveToNext();
    }

    if (expireAll)
        q = "DELETE FROM headers WHERE read=1";
    else
        q = "DELETE FROM headers WHERE read=1 AND read_unixdate < " + currentTime + " - " + expireTime;
    dbwrite.execSQL(q);
    c.close();
    dbwrite.close();
    db.close();
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static void banUser(String decodedfrom, Context context) {
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbwrite = db.getWritableDatabase();

    Cursor c = dbwrite.rawQuery("SELECT _id FROM banned_users " + " WHERE name=" + esc(decodedfrom), null);

    if (c.getCount() > 0) {
        c.moveToFirst();/* w w w  . j  a v a  2s .c om*/
        dbwrite.execSQL("UPDATE banned_users SET bandisabled=0 WHERE _id=" + c.getInt(0));
    } else {
        ContentValues cv = new ContentValues();
        cv.put("name", decodedfrom);
        cv.put("bandisabled", 0);
        dbwrite.insert("banned_users", null, cv);
    }

    // Mark all the user posts as read, so they get deleted later
    dbwrite.execSQL("UPDATE headers SET read=1, read_unixdate=" + System.currentTimeMillis()
            + " WHERE from_header=" + esc(decodedfrom));

    c.close();
    dbwrite.close();
    db.close();
}

From source file:net.naonedbus.manager.impl.CommentaireManager.java

@Override
public Commentaire getSingleFromCursor(final Cursor c) {
    final Commentaire commentaire = new Commentaire();
    commentaire.setId(c.getInt(mColId));
    commentaire.setCodeLigne(c.getString(mColCodeLigne));
    commentaire.setCodeSens(c.getString(mColCodeSens));
    commentaire.setCodeArret(c.getString(mColCodeArret));
    commentaire.setMessage(c.getString(mColMessage));
    commentaire.setSource(c.getString(mColSource));
    commentaire.setTimestamp(c.getLong(mColTimestamp));
    return commentaire;
}

From source file:net.nordist.lloydproof.CorrectionStorage.java

private JSONObject getNextAsJSONObject(Cursor cursor) throws JSONException {
    JSONObject jobject = new JSONObject();
    jobject.put("sync_id", cursor.getInt(0));
    jobject.put("current_text", cursor.getString(1));
    return jobject;
}

From source file:io.coldstart.android.Trap.java

public Trap(Cursor cursor) {
    //{ "trapID","trapHostName","trapIP","trapDate","trapUptime","trapPayload","trapRead" };
    this.trapID = cursor.getInt(0);
    this.Hostname = cursor.getString(1);
    this.IP = cursor.getString(2);
    this.date = cursor.getString(3);
    this.uptime = cursor.getString(4);
    this.trap = cursor.getString(5);
    int read = cursor.getInt(6);

    if (read == 0) {
        this.read = false;
    } else {//from w  ww  .ja  v  a  2 s  .  co  m
        this.read = true;
    }

    try {
        this.trapCount = cursor.getInt(7);

        Log.e("TrapCount", Integer.toString(this.trapCount));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.coldstart.android.Trap.java

public Trap(Cursor cursor, boolean noCount) {
    //{ "trapID","trapHostName","trapIP","trapDate","trapUptime","trapPayload","trapRead" };
    this.trapID = cursor.getInt(0);
    this.Hostname = cursor.getString(1);
    this.IP = cursor.getString(2);
    this.date = cursor.getString(3);
    this.uptime = cursor.getString(4);
    this.trap = cursor.getString(5);
    int read = cursor.getInt(6);

    if (read == 0) {
        this.read = false;
    } else {//from  w  w w  .j  av a 2s  .c om
        this.read = true;
    }
}

From source file:com.android.unit_tests.CheckinProviderTest.java

@MediumTest
public void testStatsUpdate() {
    ContentResolver r = getContext().getContentResolver();

    // First, delete any existing data associated with the TEST tag.
    Uri uri = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 0, 0);
    assertNotNull(uri);/*w  w w  . j av  a  2  s. c  o  m*/
    assertEquals(1, r.delete(uri, null, null));
    assertFalse(r.query(uri, null, null, null, null).moveToNext());

    // Now, add a known quantity to the TEST tag.
    Uri u2 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 1, 0.5);
    assertFalse(uri.equals(u2));

    Cursor c = r.query(u2, null, null, null, null);
    assertTrue(c.moveToNext());
    assertEquals(1, c.getInt(c.getColumnIndex(Checkin.Stats.COUNT)));
    assertEquals(0.5, c.getDouble(c.getColumnIndex(Checkin.Stats.SUM)));
    assertFalse(c.moveToNext()); // Only one.

    // Add another known quantity to TEST (should sum with the first).
    Uri u3 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, 2, 1.0);
    assertEquals(u2, u3);
    c.requery();
    assertTrue(c.moveToNext());
    assertEquals(3, c.getInt(c.getColumnIndex(Checkin.Stats.COUNT)));
    assertEquals(1.5, c.getDouble(c.getColumnIndex(Checkin.Stats.SUM)));
    assertFalse(c.moveToNext()); // Only one.

    // Now subtract the values; the whole row should disappear.
    Uri u4 = Checkin.updateStats(r, Checkin.Stats.Tag.TEST, -3, -1.5);
    assertNull(u4);
    c.requery();
    assertFalse(c.moveToNext()); // Row has been deleted.
    c.close();
}