Example usage for android.content ContentUris parseId

List of usage examples for android.content ContentUris parseId

Introduction

In this page you can find the example usage for android.content ContentUris parseId.

Prototype

public static long parseId(Uri contentUri) 

Source Link

Document

Converts the last path segment to a long.

Usage

From source file:cz.maresmar.sfm.view.portal.PortalDetailFragment.java

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);

    // Show warning if portal will be auto-updated
    if (isVisibleToUser && mPortalUri != null) {
        Long portalId = ContentUris.parseId(mPortalUri);

        if (portalId < ProviderContract.CUSTOM_DATA_OFFSET
                && mPrefs.getBoolean(SettingsContract.UPDATE_PORTALS_AUTOMATICALLY,
                        SettingsContract.UPDATE_PORTALS_AUTOMATICALLY_DEFAULT)) {
            showUpdateOverrideWarning();
        }/*  ww  w  . j  a  v  a2s .c  o  m*/
    }
}

From source file:org.gege.caldavsyncadapter.caldav.entities.CalendarEvent.java

public java.util.ArrayList<ContentValues> getReminders() {
    java.util.ArrayList<ContentValues> Result = new java.util.ArrayList<ContentValues>();
    ContentValues Reminder;/*from   w w  w  . ja v a  2s  .  c o m*/

    /*
     * http://sourceforge.net/tracker/?func=detail&aid=3021704&group_id=107024&atid=646395
     */

    net.fortuna.ical4j.model.component.VEvent event = (VEvent) this.calendarComponent;

    //ComponentList ComList = this.calendar.getComponents(Component.VALARM);
    ComponentList ComList = event.getAlarms();

    if (ComList != null) {
        for (Object objCom : ComList) {
            Component Com = (Component) objCom;
            Reminder = new ContentValues();

            //Property ACTION = Com.getProperty("ACTION");
            Property TRIGGER = Com.getProperty("TRIGGER");
            if (TRIGGER != null) {
                Dur Duration = new Dur(TRIGGER.getValue());
                //if (ACTION.getValue().equals("DISPLAY"))

                int intDuration = Duration.getMinutes() + Duration.getHours() * 60
                        + Duration.getDays() * 60 * 24;

                Reminder.put(Reminders.EVENT_ID, ContentUris.parseId(mAndroidEventUri));
                Reminder.put(Reminders.METHOD, Reminders.METHOD_ALERT);
                Reminder.put(Reminders.MINUTES, intDuration);

                Result.add(Reminder);
            }
        }
    }
    return Result;
}

From source file:org.totschnig.myexpenses.activity.AccountEdit.java

@Override
public void onPostExecute(Object result) {
    if (result == null) {
        Toast.makeText(this, "Unknown error while saving account", Toast.LENGTH_SHORT).show();
        return;/*w ww. j  a  v a 2  s . c o  m*/
    }
    Intent intent = new Intent();
    intent.putExtra(DatabaseConstants.KEY_ROWID, ContentUris.parseId((Uri) result));
    setResult(RESULT_OK, intent);
    finish();
    //no need to call super after finish
}

From source file:org.jonblack.bluetrack.activities.LiveTrackingFragment.java

/**
 * Adds a tracking session to the database.
 *///from  ww w .  jav  a 2s  .co  m
private void addSession() {
    Log.i(TAG, "Adding session.");

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = new Date();

    ContentValues values = new ContentValues();
    values.put("start_date_time", dateFormat.format(date));
    Uri uri = getActivity().getContentResolver().insert(SessionTable.CONTENT_URI, values);

    mSessionId = ContentUris.parseId(uri);

    assert (mSessionId != -1);
}

From source file:itreverie.weatherapp.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//from w w w  . j  av a2s .  c o m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
private long addLocation(String locationSetting, String cityName, double lat, double lon) {

    Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon);

    // First, check if the location with this city name exists in the db
    Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (cursor.moveToFirst()) {
        Log.v(LOG_TAG, "Found it in the database!");
        int locationIdIndex = cursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        return cursor.getLong(locationIdIndex);
    } else {
        Log.v(LOG_TAG, "Didn't find it in the database, inserting now!");
        ContentValues locationValues = new ContentValues();
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        return ContentUris.parseId(locationInsertUri);
    }
}

From source file:com.csipsimple.db.DBProvider.java

@Override
public int delete(Uri uri, String where, String[] whereArgs) {

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    String finalWhere;//w  w  w  .  j  a  v  a2s.co m
    int count = 0;
    int matched = URI_MATCHER.match(uri);
    Uri regUri = uri;

    List<String> possibles = getPossibleFieldsForType(matched);
    checkSelection(possibles, where);

    ArrayList<Long> oldRegistrationsAccounts = null;

    switch (matched) {
    case ACCOUNTS:
        count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, where, whereArgs);
        break;
    case ACCOUNTS_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case CALLLOGS:
        count = db.delete(SipManager.CALLLOGS_TABLE_NAME, where, whereArgs);
        break;
    case CALLLOGS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri),
                where);
        count = db.delete(SipManager.CALLLOGS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case FILTERS:
        count = db.delete(SipManager.FILTERS_TABLE_NAME, where, whereArgs);
        break;
    case FILTERS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipManager.FILTERS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case MESSAGES:
        count = db.delete(SipMessage.MESSAGES_TABLE_NAME, where, whereArgs);
        break;
    case MESSAGES_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipMessage.MESSAGES_TABLE_NAME, finalWhere, whereArgs);
        break;
    case THREADS_ID:
        String from = uri.getLastPathSegment();
        if (!TextUtils.isEmpty(from)) {
            count = db.delete(SipMessage.MESSAGES_TABLE_NAME, MESSAGES_THREAD_SELECTION,
                    new String[] { from, from });
        } else {
            count = 0;
        }
        regUri = SipMessage.MESSAGE_URI;
        break;
    case ACCOUNTS_STATUS:
        oldRegistrationsAccounts = new ArrayList<Long>();
        synchronized (profilesStatus) {
            for (Long accId : profilesStatus.keySet()) {
                oldRegistrationsAccounts.add(accId);
            }
            profilesStatus.clear();
        }
        break;
    case ACCOUNTS_STATUS_ID:
        long id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            profilesStatus.remove(id);
        }
        break;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    getContext().getContentResolver().notifyChange(regUri, null);

    if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) {
        long rowId = ContentUris.parseId(uri);
        if (rowId >= 0) {
            if (matched == ACCOUNTS_ID) {
                broadcastAccountDelete(rowId);
            } else if (matched == ACCOUNTS_STATUS_ID) {
                broadcastRegistrationChange(rowId);
            }
        }
    }
    if (matched == FILTERS || matched == FILTERS_ID) {
        Filter.resetCache();
    }
    if (matched == ACCOUNTS_STATUS && oldRegistrationsAccounts != null) {
        for (Long accId : oldRegistrationsAccounts) {
            if (accId != null) {
                broadcastRegistrationChange(accId);
            }
        }
    }

    return count;
}

From source file:net.voxcorp.voxmobile.db.DBProvider.java

@Override
public int delete(Uri uri, String where, String[] whereArgs) {

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    String finalWhere;//  w  w w. j  a v  a 2s.  c o m
    int count = 0;
    int matched = URI_MATCHER.match(uri);
    Uri regUri = uri;

    List<String> possibles = getPossibleFieldsForType(matched);
    checkSelection(possibles, where);

    ArrayList<Long> oldRegistrationsAccounts = null;

    switch (matched) {
    case ACCOUNTS:
        count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, where, whereArgs);
        break;
    case ACCOUNTS_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipProfile.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipProfile.ACCOUNTS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case CALLLOGS:
        count = db.delete(SipManager.CALLLOGS_TABLE_NAME, where, whereArgs);
        break;
    case CALLLOGS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(CallLog.Calls._ID + " = " + ContentUris.parseId(uri),
                where);
        count = db.delete(SipManager.CALLLOGS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case FILTERS:
        count = db.delete(SipManager.FILTERS_TABLE_NAME, where, whereArgs);
        break;
    case FILTERS_ID:
        finalWhere = DatabaseUtilsCompat.concatenateWhere(Filter._ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipManager.FILTERS_TABLE_NAME, finalWhere, whereArgs);
        break;
    case MESSAGES:
        count = db.delete(SipMessage.MESSAGES_TABLE_NAME, where, whereArgs);
        break;
    case MESSAGES_ID:
        finalWhere = DatabaseUtilsCompat
                .concatenateWhere(SipMessage.FIELD_ID + " = " + ContentUris.parseId(uri), where);
        count = db.delete(SipMessage.MESSAGES_TABLE_NAME, finalWhere, whereArgs);
        break;
    case THREADS_ID:
        String from = uri.getLastPathSegment();
        if (!TextUtils.isEmpty(from)) {
            count = db.delete(SipMessage.MESSAGES_TABLE_NAME, MESSAGES_THREAD_SELECTION,
                    new String[] { from, from });
        } else {
            count = 0;
        }
        regUri = SipMessage.MESSAGE_URI;
        break;
    case ACCOUNTS_STATUS:
        oldRegistrationsAccounts = new ArrayList<Long>();
        synchronized (profilesStatus) {
            for (Long accId : profilesStatus.keySet()) {
                oldRegistrationsAccounts.add(accId);
            }
            profilesStatus.clear();
        }
        break;
    case ACCOUNTS_STATUS_ID:
        long id = ContentUris.parseId(uri);
        synchronized (profilesStatus) {
            profilesStatus.remove(id);
        }
        break;
    default:
        throw new IllegalArgumentException(UNKNOWN_URI_LOG + uri);
    }

    getContext().getContentResolver().notifyChange(regUri, null);

    if (matched == ACCOUNTS_ID || matched == ACCOUNTS_STATUS_ID) {
        long rowId = ContentUris.parseId(uri);
        if (rowId >= 0) {
            if (matched == ACCOUNTS_ID) {
                broadcastAccountChange(rowId);
            } else if (matched == ACCOUNTS_STATUS_ID) {
                broadcastRegistrationChange(rowId);
            }
        }
    }
    if (matched == FILTERS || matched == FILTERS_ID) {
        Filter.resetCache();
    }
    if (matched == ACCOUNTS_STATUS && oldRegistrationsAccounts != null) {
        for (Long accId : oldRegistrationsAccounts) {
            if (accId != null) {
                broadcastRegistrationChange(accId);
            }
        }
    }

    return count;
}

From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java

private void updateStorageInfo(String updated_info) {

    //as far as I think, this should receive all the information about all four products
    //so whenever we substitute some product, the original one will not be kept in there
    //or we need some level of delete functionality? or do we need a sync adapter?
    //is this a good idea? what happens when the number of item increases?

    try {//from  w w  w .j  ava 2  s.  c  om
        DataDbHelper dbHelper = new DataDbHelper(this);
        SQLiteDatabase database = dbHelper.getWritableDatabase();

        database.delete(DataContract.ItemEntry.TABLE_NAME, null, null);
        database.execSQL(
                "DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + DataContract.ItemEntry.TABLE_NAME + "'");

        //get this valueArray from the string
        JSONArray valueArray = new JSONArray(updated_info);
        for (int lc = 0; lc < valueArray.length(); ++lc) {
            JSONObject infoJson = valueArray.getJSONObject(lc);
            //everything is the same as following code
            ContentValues newValues = new ContentValues();
            newValues.put(DataContract.ItemEntry.COLUMN_REMAINING_NUM, infoJson.getInt("remaining_num"));
            newValues.put(DataContract.ItemEntry.COLUMN_SHORT_DESC, infoJson.getString("short_desc"));
            newValues.put(DataContract.ItemEntry.COLUMN_PRICE, infoJson.getString("item_price"));
            newValues.put(DataContract.ItemEntry.COLUMN_ITEM_NAME, infoJson.getString("item_name"));
            Uri returnedUri = getContentResolver().insert(DataContract.ItemEntry.CONTENT_URI, newValues);
            Log.i(TAG, "inserted row num " + ContentUris.parseId(returnedUri));
        }

        database.close();
        dbHelper.close();
    } catch (JSONException e) {
        Log.e(TAG, "error when parsing Json");
    }
}

From source file:com.aafr.alfonso.sunshine.app.service.SunshineService.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//from  w ww .jav a 2 s .co m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
private long addLocation(String locationSetting, String cityName, double lat, double lon) {
    long locationId;

    Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon);

    // First, check if the location with this city name exists in the db
    Cursor locationCursor = this.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (locationCursor.moveToFirst()) {
        int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        // Now that the content provider is set up, inserting rows of data is pretty simple.
        // First create a ContentValues object to hold the data you want to insert.
        ContentValues locationValues = new ContentValues();

        // Then add the data, along with the corresponding name of the data type,
        // so the content provider knows what kind of value is being inserted.
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        // Finally, insert location data into the database.
        Uri insertedUri = this.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        // The resulting URI contains the ID for the row.  Extract the locationId from the Uri.
        locationId = ContentUris.parseId(insertedUri);
    }

    // Always close our cursor
    if (null != locationCursor)
        locationCursor.close();

    // Wait, that worked?  Yes!
    return locationId;
}

From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {/*  ww w. j a  va2s.c om*/

    Context context = getContext();

    App.getApiManager().getEarthquakeService().getData().enqueue(new Callback<EarthquakeObject>() {
        @Override
        public void onResponse(Call<EarthquakeObject> call, Response<EarthquakeObject> response) {
            EarthquakeObject earthquake = response.body();

            Vector<ContentValues> cVVector = new Vector<>(earthquake.getFeatures().size());

            double currentBiggest = 0.0;
            ContentValues notifyValues = null;

            for (Feature each : earthquake.getFeatures()) {

                ContentValues earthquakeValues = new ContentValues();

                earthquakeValues.put(EarthquakeColumns.PLACE, each.getProperties().getPlace());
                earthquakeValues.put(EarthquakeColumns.ID_EARTH, each.getId());
                earthquakeValues.put(EarthquakeColumns.MAG, each.getProperties().getMag());
                earthquakeValues.put(EarthquakeColumns.TYPE, each.getProperties().getType());
                earthquakeValues.put(EarthquakeColumns.ALERT, each.getProperties().getAlert());
                earthquakeValues.put(EarthquakeColumns.TIME, each.getProperties().getTime());
                earthquakeValues.put(EarthquakeColumns.URL, each.getProperties().getUrl());
                earthquakeValues.put(EarthquakeColumns.DETAIL, each.getProperties().getDetail());
                earthquakeValues.put(EarthquakeColumns.DEPTH, each.getGeometry().getCoordinates().get(2));
                earthquakeValues.put(EarthquakeColumns.LONGITUDE, each.getGeometry().getCoordinates().get(0));
                earthquakeValues.put(EarthquakeColumns.LATITUDE, each.getGeometry().getCoordinates().get(1));

                LatLng latLng = new LatLng(each.getGeometry().getCoordinates().get(1),
                        each.getGeometry().getCoordinates().get(0));
                LatLng location = LocationUtils.getLocation(context);
                earthquakeValues.put(EarthquakeColumns.DISTANCE, LocationUtils.getDistance(latLng, location));

                cVVector.add(earthquakeValues);

                if (each.getProperties().getMag() != null && each.getProperties().getMag() > currentBiggest) {
                    currentBiggest = each.getProperties().getMag();
                    notifyValues = new ContentValues(earthquakeValues);
                    notifyValues.put(EarthquakeColumns.PLACE,
                            Utilities.formatEarthquakePlace(each.getProperties().getPlace()));
                }
            }

            int inserted = 0;
            // add to database
            ContentResolver resolver = context.getContentResolver();

            if (cVVector.size() > 0) {
                ContentValues[] cvArray = new ContentValues[cVVector.size()];
                cVVector.toArray(cvArray);
                inserted = resolver.bulkInsert(EarthquakeColumns.CONTENT_URI, cvArray);
            }

            // Set the date to day minus one to delete old data from the database
            Date date = new Date();
            date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS);

            int deleted = resolver.delete(EarthquakeColumns.CONTENT_URI, EarthquakeColumns.TIME + " <= ?",
                    new String[] { String.valueOf(date.getTime()) });
            Log.v(TAG, "Service Complete. " + inserted + " Inserted, " + deleted + " deleted");
            sendNotification(notifyValues);
        }

        @Override
        public void onFailure(Call<EarthquakeObject> call, Throwable t) {
            Log.e(TAG, "onFailure: " + t.toString());
        }
    });

    App.getNewsManager().getNewsService().getNews().enqueue(new Callback<Rss>() {
        @Override
        public void onResponse(Call<Rss> call, Response<Rss> response) {
            Channel news = response.body().getChannel();

            Vector<ContentValues> cVVector = new Vector<>(news.getItem().size());

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z",
                    Locale.getDefault());
            Date date = new Date();

            for (Item each : news.getItem()) {

                ContentValues weatherValues = new ContentValues();

                try {
                    date = simpleDateFormat.parse(each.getPubDate());
                } catch (ParseException e) {
                    Log.e(TAG, "e:" + e);
                }

                weatherValues.put(NewsColumns.DATE, date.getTime());
                weatherValues.put(NewsColumns.TITLE, each.getTitle());
                weatherValues.put(NewsColumns.DESCRIPTION,
                        Html.toHtml(new SpannedString(each.getDescription())));
                weatherValues.put(NewsColumns.URL, each.getLink());
                weatherValues.put(NewsColumns.GUID, each.getGuid().getContent());

                cVVector.add(weatherValues);
            }

            int inserted = 0;
            // add to database
            ContentResolver resolver = getContext().getContentResolver();

            if (cVVector.size() > 0) {

                // Student: call bulkInsert to add the weatherEntries to the database here
                ContentValues[] cvArray = new ContentValues[cVVector.size()];
                cVVector.toArray(cvArray);
                inserted = resolver.bulkInsert(NewsColumns.CONTENT_URI, cvArray);
            }

            // Set the date to day minus two to delete old data from the database
            date = new Date();
            date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS * 3);

            int deleted = resolver.delete(NewsColumns.CONTENT_URI, NewsColumns.DATE + " <= ?",
                    new String[] { String.valueOf(date.getTime()) });
        }

        @Override
        public void onFailure(Call<Rss> call, Throwable t) {
            Log.e(TAG, "onFailure: " + t.toString());
        }
    });

    // TODO: 4/22/16 possible refactoring 
    //checking the last update and notify if it' the first of the day
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String lastNotificationKey = context.getString(R.string.sharedprefs_key_last_countupdate);
    long lastSync = prefs.getLong(lastNotificationKey, DateUtils.DAY_IN_MILLIS);

    if (System.currentTimeMillis() - lastSync >= Utilities.getSyncIntervalPrefs(context)
            * DateUtils.SECOND_IN_MILLIS) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        Date date = new Date(System.currentTimeMillis());

        String startTime[] = new String[] { simpleDateFormat.format(date.getTime() - DateUtils.YEAR_IN_MILLIS),
                simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS * 30),
                simpleDateFormat.format(date.getTime() - DateUtils.WEEK_IN_MILLIS),
                simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS) };

        String endTime = simpleDateFormat.format(date);

        int iterator = 1;
        while (iterator < CountColumns.ALL_COLUMNS.length) {
            final int round = iterator;

            App.getApiManager().getEarthquakeService().getEarthquakeStats(startTime[round - 1], endTime)
                    .enqueue(new Callback<CountEarthquakes>() {
                        @Override
                        public void onResponse(Call<CountEarthquakes> call,
                                Response<CountEarthquakes> response) {
                            ContentValues count = new ContentValues();
                            count.put(CountColumns.ALL_COLUMNS[round], response.body().getCount());

                            ContentResolver contentResolver = context.getContentResolver();

                            Cursor cursor = contentResolver.query(CountColumns.CONTENT_URI, null, null, null,
                                    null);

                            if (cursor != null) {
                                if (cursor.getCount() < 1) {
                                    long inserted = ContentUris
                                            .parseId(contentResolver.insert(CountColumns.CONTENT_URI, count));
                                    //Log.d(TAG, "inserted:" + inserted);
                                } else {
                                    int updated = contentResolver.update(CountColumns.CONTENT_URI, count,
                                            CountColumns._ID + " = ?", new String[] { "1" });
                                    //Log.d(TAG, "updated: " + updated);
                                }
                                cursor.close();
                            }

                        }

                        @Override
                        public void onFailure(Call<CountEarthquakes> call, Throwable t) {
                            Log.e(TAG, "Error: " + t);
                        }
                    });
            iterator++;
        }

        //refreshing last sync
        prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).apply();
    }

    // notify PagerActivity that data has been updated
    context.getContentResolver().notifyChange(EarthquakeColumns.CONTENT_URI, null, false);
    context.getContentResolver().notifyChange(NewsColumns.CONTENT_URI, null, false);
    context.getContentResolver().notifyChange(CountColumns.CONTENT_URI, null, false);

    updateWidgets();
}