@Override protected void onHandleIntent(Intent intent) { if (intent != null) { final String action = intent.getAction(); if (SunshineSyncAdapter.ACTION_DATA_UPDATED.equals(action)) { String location = Utility.getPreferredLocation(this); Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate( location, System.currentTimeMillis()); Cursor cursor = getContentResolver() .query( weatherForLocationUri, FORECAST_COLUMNS, null, null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC"); if (cursor.moveToFirst()) { int weatherId = cursor.getInt(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID)); String desc = cursor.getString( cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC)); double high = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP)); double low = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP)); handleWatchfaceUpdate(weatherId, desc, high, low); } cursor.close(); } } }
@Override public Loader<Cursor> onCreateLoader(int i, Bundle bundle) { // This is called when a new Loader needs to be created. This // fragment only uses one loader, so we don't care about checking the id. // To only show current and future dates, filter the query to return weather only for // dates after or including today. // Sort order: Ascending, by date. String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC"; String locationSetting = Utility.getPreferredLocation(getActivity()); Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate( locationSetting, System.currentTimeMillis()); return new CursorLoader( getActivity(), weatherForLocationUri, FORECAST_COLUMNS, null, null, sortOrder); }