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:fr.eoit.activity.loader.InvestItemsLoader.java

private static SparseItemBeanArray getInvestParentBlueprint(Context context, long itemId) {
    SparseItemBeanArray items = new SparseItemBeanArray();

    final Cursor cursor = context.getContentResolver()
            .query(ContentUris.withAppendedId(Blueprint.CONTENT_ITEM_ID_URI_BASE, itemId),
                    new String[] { Blueprint._ID, Blueprint.COLUMN_NAME_NAME,
                            Blueprint.COLUMN_NAME_PARENT_TYPE_ID, Blueprint.COLUMN_NAME_TECH_LEVEL,
                            Blueprint.COLUMN_NAME_DECRYPTOR_ID },
                    null, null, null);/*w w w. j  a v  a 2  s . c o  m*/

    try {
        if (DbUtil.hasAtLeastOneRow(cursor)) {

            ItemBeanWithMaterials item = new ItemBeanWithMaterials();
            item.id = cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint._ID));
            item.name = cursor.getString(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_NAME));
            //item.price = PricesUtils.getPriceOrNaN(cursor);
            item.quantity = 1;
            //item.chosenPriceId = cursor.getShort(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID));
            item.volume = Double.NaN;

            items.append(item);

            int techLevel = cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_TECH_LEVEL));
            int parentTypeId = cursor
                    .getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PARENT_TYPE_ID));
            int decryptorId = cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_DECRYPTOR_ID));

            if (techLevel == 2) {
                final Cursor cursorDataInterface = context.getContentResolver().query(
                        ContentUris.withAppendedId(Blueprint.CONTENT_ID_URI_INVENTION_BASE, parentTypeId),
                        new String[] { "i." + Item._ID + " AS " + Item._ID, ItemMaterials.COLUMN_NAME_QUANTITY,
                                Item.COLUMN_NAME_CHOSEN_PRICE_ID, Item.COLUMN_NAME_NAME,
                                Prices.COLUMN_NAME_BUY_PRICE, Prices.COLUMN_NAME_SELL_PRICE,
                                Prices.COLUMN_NAME_OWN_PRICE, Prices.COLUMN_NAME_PRODUCE_PRICE },
                        null, new String[] { decryptorId == 0 ? null : String.valueOf(decryptorId) },
                        "i." + Item._ID + " ASC");

                try {
                    if (DbUtil.hasAtLeastOneRow(cursorDataInterface)) {
                        while (!cursorDataInterface.isAfterLast()) {

                            item = new ItemBeanWithMaterials();
                            item.id = cursorDataInterface
                                    .getInt(cursorDataInterface.getColumnIndexOrThrow(Item._ID));
                            item.name = cursorDataInterface.getString(
                                    cursorDataInterface.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME));
                            item.price = PricesUtils.getPriceOrNaN(cursorDataInterface);
                            item.quantity = 1;
                            item.chosenPriceId = cursorDataInterface.getShort(cursorDataInterface
                                    .getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID));
                            item.volume = Double.NaN;

                            if (EOITConst.Invention.DATA_INTERFACE_IDS.contains((long) item.id))
                                items.append(item);

                            cursorDataInterface.moveToNext();
                        }
                    }
                } finally {
                    cursorDataInterface.close();
                }
            }
        }
    } finally {
        cursor.close();
    }

    return items;
}

From source file:com.awt.supark.CarListFragment.java

@Nullable
@Override//from   ww w.  j  a  v a 2  s  .c  om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_list_layout, container, false);
    listview = (ListView) view.findViewById(R.id.listview);

    // Creating database if it's not exist yet
    db = SQLiteDatabase.openDatabase(getContext().getFilesDir().getPath() + "/carDB.db", null,
            SQLiteDatabase.CREATE_IF_NECESSARY);

    //------------------------ Creating the car list ---------------------------
    Cursor d = db.rawQuery("SELECT * FROM cars", null);

    for (d.moveToFirst(); !d.isAfterLast(); d.moveToNext()) {
        Car car = new Car();

        car.setName(d.getString(d.getColumnIndex("car_name"))); // set name
        car.setLicens(d.getString(d.getColumnIndex("car_license"))); // set license
        car.setSqlid(d.getInt(d.getColumnIndex("car_id")));
        car.setGeneric(d.getInt(d.getColumnIndex("isgeneric")));

        // Retrieves the parking state of the car
        switch (d.getInt(d.getColumnIndex("parkedstate"))) {
        case 0:
            car.setState(getResources().getString(R.string.free));
            break;
        case 1:
            car.setState(getResources().getString(R.string.parked));
            break;
        }
        car.setRemaining(
                (int) (d.getLong(d.getColumnIndex("parkeduntil")) - ((System.currentTimeMillis() / 1000L))));
        carArray.add(car);
    }

    d.close();
    db.close();

    // List adapter
    adapter = new CarListAdapter(getActivity(), carArray);

    // Turning off dividers
    listview.setDivider(null);
    listview.setDividerHeight(0);
    listview.setClipToPadding(false);
    listview.setPadding(0, 10, 0, 100);
    listview.setAdapter(adapter);

    return view;
}

From source file:fr.eoit.activity.fragment.blueprint.ItemInvestFragment.java

@Override
public void onLoadFinished(Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor)) {
        while (!cursor.isAfterLast()) {

            int id = cursor.getInt(cursor.getColumnIndexOrThrow(Stock.COLUMN_NAME_ITEM_ID));
            long quantity = cursor.getLong(cursor.getColumnIndexOrThrow(Stock.COLUMN_NAME_QUANTITY));
            ItemBeanWithMaterials item = new ItemBeanWithMaterials();
            item.id = id;/*  w  w  w . j  a  v a 2s. c  o m*/
            item.quantity = quantity;

            stockItems.put(id, item);

            cursor.moveToNext();
        }
    }

    //SparseItemBeanArray remainingInvestItems = investItemsItemMap.exclude(stockItems);

    MatrixCursor investItemsMatrixCursor = EnhancedMaterialListFragment.getEmptyCursor();
    for (ItemBeanWithMaterials item : investItemsItemMap.values()) {
        EnhancedMaterialListFragment.addRowToMatrixCursor(investItemsMatrixCursor, item);
    }

    investItemsFragment.initialize(new ProductionStep("INVEST", investItemsMatrixCursor));
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    activity = (RecipeEditor) getActivity();
    tags = new ArrayList<String>();

    if (savedInstanceState != null) {
        // Load old state if we have it...
        String[] saved = savedInstanceState.getStringArray(STATE);
        if (saved != null) {
            tags.addAll(Arrays.asList(saved));
        }/*w w w .jav a  2 s. com*/
    } else {
        // ...or load an old recipe or start a new one.
        long rid = activity.getRecipeId();

        if (rid > 0) {
            RecipeBook app = (RecipeBook) activity.getApplication();
            Cursor c = app.getData().getRecipeTags(rid);

            c.moveToFirst();
            while (!c.isAfterLast()) {
                tags.add(c.getString(c.getColumnIndex(RecipeData.TT_TAG)));
                c.moveToNext();
            }

            c.close();

        } else {

        }
    }

    adapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, tags);
    return inflater.inflate(R.layout.tagsedit, container, false);
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

static void loadDays(Context context) {
    MyApp.dateInfos = new DateInfos();
    LecturesDBOpenHelper lecturesDB = new LecturesDBOpenHelper(context);

    SQLiteDatabase lecturedb = lecturesDB.getReadableDatabase();
    Cursor cursor;

    try {/*ww w  .  ja v  a  2s  .c o  m*/
        cursor = lecturedb.query(LecturesTable.NAME, LecturesDBOpenHelper.allcolumns, null, null, null, null,
                null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        lecturedb.close();
        lecturesDB.close();
        return;
    }

    if (cursor.getCount() == 0) {
        // evtl. Datenbankreset wg. DB Formatnderung -> neu laden
        cursor.close();
        lecturesDB.close();
        lecturedb.close();
        return;
    }

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        int day = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DAY));
        String date = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DATE));

        DateInfo dateItem = new DateInfo(day, date);
        if (!MyApp.dateInfos.contains(dateItem)) {
            MyApp.dateInfos.add(dateItem);
        }
        cursor.moveToNext();
    }
    cursor.close();

    for (DateInfo dateInfo : MyApp.dateInfos) {
        MyApp.LogDebug(LOG_TAG, "DateInfo: " + dateInfo);
    }
    lecturesDB.close();
    lecturedb.close();
}

From source file:fr.eoit.activity.fragment.mining.session.ObjectivesFragment.java

@Override
protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) {
    MatrixCursor objectivesItemCursur = getEmptyCursor();

    cursor.moveToFirst();//  w  w  w.j av a  2  s . c om
    while (!cursor.isAfterLast()) {

        int id = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID));
        String name = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME));
        ItemBeanWithMaterials item = new ItemBeanWithMaterials();
        item.id = id;
        item.name = name;
        item.quantity = objectives.get(id);

        addRowToMatrixCursor(objectivesItemCursur, item);

        cursor.moveToNext();
    }

    adapter.setViewBinder(new MaterialsListViewBinderWithTotalPriceAndVolume());
    adapter.swapCursor(objectivesItemCursur);
}

From source file:fr.eoit.activity.fragment.mining.session.ReprocessFragment.java

@Override
protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) {
    MatrixCursor objectivesItemCursur = getEmptyCursor();

    cursor.moveToFirst();/*from   w w  w .ja  va2 s  .c  om*/
    while (!cursor.isAfterLast()) {

        int id = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID));
        String name = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME));
        ItemBeanWithMaterials item = new ItemBeanWithMaterials();
        item.id = id;
        item.name = name;
        item.quantity = minerals.get(id).quantity;
        item.price = PricesUtils.getPriceOrNaN(cursor);
        item.volume = cursor.getDouble(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_VOLUME));

        totalPrice += item.quantity * item.price;
        totalVolume += item.quantity * item.volume;

        addRowToMatrixCursor(objectivesItemCursur, item);

        cursor.moveToNext();
    }

    adapter.setViewBinder(new MaterialsListViewBinderWithTotalPriceAndVolume());
    adapter.swapCursor(objectivesItemCursur);
}

From source file:com.android.calendar.alerts.AlarmScheduler.java

/**
 * Queries for all the reminders of the events in the instancesCursor, and schedules
 * the alarm for the next upcoming reminder.
 *//*w  w  w . ja va2  s .  co  m*/
private static void queryNextReminderAndSchedule(Cursor instancesCursor, Context context,
        ContentResolver contentResolver, AlarmManagerInterface alarmManager, int batchSize,
        long currentMillis) {
    if (AlertService.DEBUG) {
        int eventCount = instancesCursor.getCount();
        if (eventCount == 0) {
            Log.d(TAG, "No events found starting within 1 week.");
        } else {
            Log.d(TAG, "Query result count for events starting within 1 week: " + eventCount);
        }
    }

    // Put query results of all events starting within some interval into map of event ID to
    // local start time.
    Map<Integer, List<Long>> eventMap = new HashMap<Integer, List<Long>>();
    Time timeObj = new Time();
    long nextAlarmTime = Long.MAX_VALUE;
    int nextAlarmEventId = 0;
    instancesCursor.moveToPosition(-1);
    while (!instancesCursor.isAfterLast()) {
        int index = 0;
        eventMap.clear();
        StringBuilder eventIdsForQuery = new StringBuilder();
        eventIdsForQuery.append('(');
        while (index++ < batchSize && instancesCursor.moveToNext()) {
            int eventId = instancesCursor.getInt(INSTANCES_INDEX_EVENTID);
            long begin = instancesCursor.getLong(INSTANCES_INDEX_BEGIN);
            boolean allday = instancesCursor.getInt(INSTANCES_INDEX_ALL_DAY) != 0;
            long localStartTime;
            if (allday) {
                // Adjust allday to local time.
                localStartTime = Utils.convertAlldayUtcToLocal(timeObj, begin, Time.getCurrentTimezone());
            } else {
                localStartTime = begin;
            }
            List<Long> startTimes = eventMap.get(eventId);
            if (startTimes == null) {
                startTimes = new ArrayList<Long>();
                eventMap.put(eventId, startTimes);
                eventIdsForQuery.append(eventId);
                eventIdsForQuery.append(",");
            }
            startTimes.add(localStartTime);

            // Log for debugging.
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                timeObj.set(localStartTime);
                StringBuilder msg = new StringBuilder();
                msg.append("Events cursor result -- eventId:").append(eventId);
                msg.append(", allDay:").append(allday);
                msg.append(", start:").append(localStartTime);
                msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")");
                Log.d(TAG, msg.toString());
            }
        }
        if (eventIdsForQuery.charAt(eventIdsForQuery.length() - 1) == ',') {
            eventIdsForQuery.deleteCharAt(eventIdsForQuery.length() - 1);
        }
        eventIdsForQuery.append(')');

        // Query the reminders table for the events found.
        Cursor cursor = null;
        try {
            cursor = contentResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
                    REMINDERS_WHERE + eventIdsForQuery, null, null);

            // Process the reminders query results to find the next reminder time.
            cursor.moveToPosition(-1);
            while (cursor.moveToNext()) {
                int eventId = cursor.getInt(REMINDERS_INDEX_EVENT_ID);
                int reminderMinutes = cursor.getInt(REMINDERS_INDEX_MINUTES);
                List<Long> startTimes = eventMap.get(eventId);
                if (startTimes != null) {
                    for (Long startTime : startTimes) {
                        long alarmTime = startTime - reminderMinutes * DateUtils.MINUTE_IN_MILLIS;
                        if (alarmTime > currentMillis && alarmTime < nextAlarmTime) {
                            nextAlarmTime = alarmTime;
                            nextAlarmEventId = eventId;
                        }

                        if (Log.isLoggable(TAG, Log.DEBUG)) {
                            timeObj.set(alarmTime);
                            StringBuilder msg = new StringBuilder();
                            msg.append("Reminders cursor result -- eventId:").append(eventId);
                            msg.append(", startTime:").append(startTime);
                            msg.append(", minutes:").append(reminderMinutes);
                            msg.append(", alarmTime:").append(alarmTime);
                            msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")");
                            Log.d(TAG, msg.toString());
                        }
                    }
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    // Schedule the alarm for the next reminder time.
    if (nextAlarmTime < Long.MAX_VALUE) {
        scheduleAlarm(context, nextAlarmEventId, nextAlarmTime, currentMillis, alarmManager);
    }
}

From source file:com.amaze.carbonfilemanager.activities.DbViewer.java

private ArrayList<String> getDbTableNames(Cursor c) {
    ArrayList<String> result = new ArrayList<>();
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        for (int i = 0; i < c.getColumnCount(); i++) {
            result.add(c.getString(i));/*www  .j  av a 2  s  .  co m*/
        }
    }
    return result;
}

From source file:com.commonsware.android.arXiv.DownloadsActivity.java

private void deleteFiles() {
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    Cursor c = dm.query(new DownloadManager.Query());
    if (c != null) {
        long[] ids = new long[c.getCount()];
        int position = 0;
        c.moveToFirst();//from  ww  w . j ava2  s  .  c  o  m
        while (!c.isAfterLast()) {
            ids[position] = c.getLong(c.getColumnIndex(DownloadManager.COLUMN_ID));
            c.moveToNext();
            position++;
        }
        dm.remove(ids);
    }
    Toast.makeText(DownloadsActivity.this, R.string.deleted_history, Toast.LENGTH_SHORT).show();
    finish();
}