Example usage for android.database Cursor requery

List of usage examples for android.database Cursor requery

Introduction

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

Prototype

@Deprecated
boolean requery();

Source Link

Document

Performs the query that created the cursor again, refreshing its contents.

Usage

From source file:com.adam.aslfms.util.Util.java

public static void deleteScrobbleFromCache(Context ctx, final ScrobblesDatabase db, final NetApp napp,
        final Cursor cursor, final int id) {
    Util.confirmDialog(ctx, ctx.getString(R.string.confirm_delete_sc).replaceAll("%1", napp.getName()),
            R.string.remove, android.R.string.cancel, new OnClickListener() {
                @Override/*from   www.  j ava2  s. c om*/
                public void onClick(DialogInterface dialog, int which) {

                    Log.d(TAG, "Will remove scrobble from cache: " + napp.getName() + ", " + id);
                    db.deleteScrobble(napp, id);
                    db.cleanUpTracks();
                    // need to refill data, otherwise the screen won't
                    // update
                    if (cursor != null)
                        cursor.requery();
                }
            });
}

From source file:com.bourke.kitchentimer.utils.Utils.java

public static boolean exportCSV(Context context, Cursor cursor) {
    if (cursor.getCount() == 0)
        return true;
    // An array to hold the rows that will be written to the CSV file.
    final int rowLenght = FoodMetaData.COLUMNS.length - 1;
    String[] row = new String[rowLenght];
    System.arraycopy(FoodMetaData.COLUMNS, 1, row, 0, rowLenght);
    CSVWriter writer = null;/*from   w  w w .jav a2 s.  c  om*/
    boolean success = false;

    try {
        writer = new CSVWriter(new FileWriter(Constants.CSV_FILE));

        // Write descriptive headers.
        writer.writeNext(row);

        int nameIndex = cursor.getColumnIndex(FoodMetaData.NAME);
        int hoursIndex = cursor.getColumnIndex(FoodMetaData.HOURS);
        int minutesIndex = cursor.getColumnIndex(FoodMetaData.MINUTES);
        int secondsIndex = cursor.getColumnIndex(FoodMetaData.SECONDS);

        if (cursor.requery()) {
            while (cursor.moveToNext()) {
                row[0] = cursor.getString(nameIndex);
                row[1] = cursor.getInt(hoursIndex) + "";
                row[2] = cursor.getInt(minutesIndex) + "";
                row[3] = cursor.getInt(secondsIndex) + "";
                // NOTE: writeNext() handles nulls in row[] gracefully.
                writer.writeNext(row);
            }
        }
        success = true;
    } catch (Exception ex) {
        Log.e("Utils", "exportCSV", ex);
    } finally {
        try {
            if (null != writer)
                writer.close();
        } catch (IOException ex) {

        }
    }
    return success;
}

From source file:com.adam.aslfms.util.Util.java

public static void deleteScrobbleFromAllCaches(Context ctx, final ScrobblesDatabase db, final Cursor cursor,
        final int id) {
    Util.confirmDialog(ctx, ctx.getString(R.string.confirm_delete_sc_from_all), R.string.remove,
            android.R.string.cancel, new OnClickListener() {
                @Override/*from  www. j a va 2 s  .  c  om*/
                public void onClick(DialogInterface dialog, int which) {

                    Log.d(TAG, "Will remove scrobble from all caches: " + id);
                    for (NetApp napp : NetApp.values())
                        db.deleteScrobble(napp, id);
                    db.cleanUpTracks();
                    // need to refill data, otherwise the screen won't
                    // update
                    if (cursor != null)
                        cursor.requery();
                }
            });
}

From source file:com.adam.aslfms.util.Util.java

public static void deleteAllScrobblesFromCache(Context ctx, final ScrobblesDatabase db, final NetApp napp,
        final Cursor cursor) {
    int numInCache = db.queryNumberOfScrobbles(napp);
    if (numInCache > 0) {
        Util.confirmDialog(ctx, ctx.getString(R.string.confirm_delete_all_sc).replaceAll("%1", napp.getName()),
                R.string.clear_cache, android.R.string.cancel, new OnClickListener() {
                    @Override//from  ww w. j a  v  a 2 s.  com
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d(TAG, "Will remove all scrobbles from cache: " + napp.getName());
                        db.deleteAllScrobbles(napp);
                        db.cleanUpTracks();
                        // need to refill data, otherwise the screen won't
                        // update
                        if (cursor != null)
                            cursor.requery();
                    }
                });
    } else {
        Toast.makeText(ctx, ctx.getString(R.string.no_scrobbles_in_cache), Toast.LENGTH_LONG).show();
    }
}

From source file:org.linkdroid.BroadcastReceiverService.java

@Override
public void onStart(Intent intent, int startId) {
    if (!Settings.isEventsEnabled(this)) {
        Log.d(TAG, "Service started but events is disabled.");
        stopSelf();/*w w  w  .  j  a  va  2 s .  c  o  m*/
        return;
    }
    LogsService.logSystemDebugMessage(this, "" + getString(R.string.broadcastreceiverservice_start));

    try {
        unregisterReceiver(receiver);
        Log.d(TAG, "unregistered receiver for service start");
    } catch (Exception e) {
        // Do Nothing
    }
    try {
        unregisterReceiver(smsReceiver);
        Log.d(TAG, "Unregistered SmsReceiver for service start");
    } catch (Exception e) {
        // Do nothing.
    }

    if (Settings.isEventsSmsEnabled(this)) {
        try {
            enableSmsReceiver();
        } catch (Exception e) {
            Log.w(TAG, e.toString());
            LogsService.logSystemDebugMessage(this, e.toString());
        }
    }

    Cursor c = intentFiltersCursor;
    c.requery();
    if (c.moveToFirst()) {
        do {
            try {
                enableIntentFilterAtCursor(c);
            } catch (Exception e) {
                Log.w(TAG, e.toString());
                LogsService.logSystemDebugMessage(this, e.toString());
            }
        } while (intentFiltersCursor.moveToNext());
    }
}

From source file:com.adam.aslfms.util.Util.java

public static void deleteAllScrobblesFromAllCaches(Context ctx, final ScrobblesDatabase db,
        final Cursor cursor) {
    int numInCache = db.queryNumberOfTracks();
    if (numInCache > 0) {
        Util.confirmDialog(ctx, ctx.getString(R.string.confirm_delete_all_sc_from_all), R.string.clear_cache,
                android.R.string.cancel, new OnClickListener() {
                    @Override//from   w  w  w. j av a  2 s.c om
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d(TAG, "Will remove all scrobbles from cache for all netapps");
                        for (NetApp napp : NetApp.values())
                            db.deleteAllScrobbles(napp);
                        db.cleanUpTracks();
                        // need to refill data, otherwise the screen won't
                        // update
                        if (cursor != null)
                            cursor.requery();
                    }
                });
    } else {
        Toast.makeText(ctx, ctx.getString(R.string.no_scrobbles_in_cache), Toast.LENGTH_LONG).show();
    }
}

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);//from   w  w w.ja  va  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();
}

From source file:com.todoroo.astrid.actfm.CommentsFragment.java

protected void refreshUpdatesList() {
    Activity activity = getActivity();/*ww  w.  jav a 2 s  . c  o m*/
    View view = getView();
    if (activity == null || view == null) {
        return;
    }

    Cursor cursor;
    ListView listView = ((ListView) view.findViewById(android.R.id.list));
    if (updateAdapter == null) {
        cursor = getCursor();
        activity.startManagingCursor(cursor);

        updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row, cursor);
        addHeaderToListView(listView);
        addFooterToListView(listView);
        listView.setAdapter(updateAdapter);
    } else {
        cursor = updateAdapter.getCursor();
        cursor.requery();
        activity.startManagingCursor(cursor);
        if (footerView != null) {
            listView.removeFooterView(footerView);
            footerView = null;
        }
    }

    listView.setVisibility(View.VISIBLE);
}

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

@MediumTest
public void testEventReport() {
    long start = System.currentTimeMillis();
    ContentResolver r = getContext().getContentResolver();
    Checkin.logEvent(r, Checkin.Events.Tag.TEST, "Test Value");

    Cursor c = r.query(Checkin.Events.CONTENT_URI, null, Checkin.Events.TAG + "=?",
            new String[] { Checkin.Events.Tag.TEST.toString() }, null);

    long id = -1;
    while (c.moveToNext()) {
        String tag = c.getString(c.getColumnIndex(Checkin.Events.TAG));
        String value = c.getString(c.getColumnIndex(Checkin.Events.VALUE));
        long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE));
        assertEquals(Checkin.Events.Tag.TEST.toString(), tag);
        if ("Test Value".equals(value) && date >= start) {
            assertTrue(id < 0);//from w w w .  j  av  a 2s. co  m
            id = c.getInt(c.getColumnIndex(Checkin.Events._ID));
        }
    }
    assertTrue(id > 0);

    int rows = r.delete(ContentUris.withAppendedId(Checkin.Events.CONTENT_URI, id), null, null);
    assertEquals(1, rows);
    c.requery();
    while (c.moveToNext()) {
        long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE));
        assertTrue(date < start); // Have deleted the only newer TEST.
    }

    c.close();
}

From source file:com.todoroo.astrid.actfm.TagUpdatesFragment.java

private void refreshUpdatesList() {

    Cursor cursor = null;
    ListView listView = ((ListView) getView().findViewById(android.R.id.list));
    if (updateAdapter == null) {
        cursor = tagDataService.getUpdates(tagData);
        getActivity().startManagingCursor(cursor);
        String fromUpdateClass = (tagData == null) ? UpdateAdapter.FROM_RECENT_ACTIVITY_VIEW
                : UpdateAdapter.FROM_TAG_VIEW;

        updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row, cursor, false, fromUpdateClass);
        addHeaderToListView(listView);//from w w w. jav  a  2 s .c om
        listView.setAdapter(updateAdapter);
    } else {
        cursor = updateAdapter.getCursor();
        cursor.requery();
        getActivity().startManagingCursor(cursor);
        populateListHeader(listHeader);
    }

    View activityContainer = getView().findViewById(R.id.no_activity_container);
    if (cursor.getCount() == 0) {
        activityContainer.setVisibility(View.VISIBLE);
        TextView textView = (TextView) activityContainer.findViewById(R.id.no_activity_message);
        if (actFmPreferenceService.isLoggedIn()) {
            textView.setText(getActivity().getString(R.string.ENA_no_comments));
        } else {
            textView.setText(getActivity().getString(R.string.UpS_no_activity_log_in));
            activityContainer.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(getActivity(), ActFmLoginActivity.class),
                            TagSettingsActivity.REQUEST_ACTFM_LOGIN);
                }
            });
        }
        listView.setVisibility(View.GONE);
    } else {
        activityContainer.setVisibility(View.GONE);
        listView.setVisibility(View.VISIBLE);
    }

    if (getActivity() instanceof TagUpdatesActivity)
        setLastViewed();
}