@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data.moveToFirst()) { detailString = convertCursorRowToUXFormat(data); if (shareProvider != null) { shareProvider.setShareIntent(createForecastShareIntent()); } mWeatherId = data.getInt(COL_WEATHER_ID); long date = data.getLong(ForecastFragment.COL_WEATHER_DATE); // POPULATE THE text views mDay.setText(Utility.getDayName(getActivity(), date)); mDate.setText(Utility.getFormattedMonthDay(getActivity(), date)); mHigh.setText( getString(R.string.format_degrees, data.getFloat(ForecastFragment.COL_WEATHER_MAX_TEMP))); mLow.setText( getString(R.string.format_degrees, data.getFloat(ForecastFragment.COL_WEATHER_MIN_TEMP))); mHumidity.setText(getString(R.string.format_humidity, data.getFloat(COL_HUMIDITY))); mPressure.setText(getString(R.string.format_pressure, data.getFloat(COL_PRESSURE))); mIcon.setImageResource(Utility.weatherCodeToArtPath(mWeatherId)); float windSpeed = data.getFloat(COL_WIND_SPEED); String windDirection = getWindDirection(data.getFloat(COL_DEGREES)); mWind.setText(getString(R.string.format_wind_kmh, windSpeed, windDirection)); if (mCompass != null) { mCompass.setAngle(degreesToRadians(data.getFloat(COL_DEGREES))); } mDescription.setText(data.getString(ForecastFragment.COL_WEATHER_DESC)); } }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { // Read weather condition ID from cursor int weatherId = data.getInt(data.getColumnIndex(WeatherEntry.COLUMN_WEATHER_ID)); // Use placeholder Image mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); // Read date from cursor and update views for day of week and date String date = data.getString(data.getColumnIndex(WeatherEntry.COLUMN_DATETEXT)); String friendlyDateText = Utility.getDayName(getActivity(), date); String dateText = Utility.getFormattedMonthDay(getActivity(), date); mFriendlyDateView.setText(friendlyDateText); mDateView.setText(dateText); // Read description from cursor and update view String description = data.getString(data.getColumnIndex(WeatherEntry.COLUMN_SHORT_DESC)); mDescriptionView.setText(description); // For accessibility, add a content description to the icon field. mIconView.setContentDescription(description); // Read high temperature from cursor and update view boolean isMetric = Utility.isMetric(getActivity()); double high = data.getDouble(data.getColumnIndex(WeatherEntry.COLUMN_MAX_TEMP)); String highString = Utility.formatTemperature(getActivity(), high, isMetric); mHighTempView.setText(highString); // Read low temperature from cursor and update view double low = data.getDouble(data.getColumnIndex(WeatherEntry.COLUMN_MIN_TEMP)); String lowString = Utility.formatTemperature(getActivity(), low, isMetric); mLowTempView.setText(lowString); // Read humidity from cursor and update view float humidity = data.getFloat(data.getColumnIndex(WeatherEntry.COLUMN_HUMIDITY)); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); // Read wind speed and direction from cursor and update view float windSpeedStr = data.getFloat(data.getColumnIndex(WeatherEntry.COLUMN_WIND_SPEED)); float windDirStr = data.getFloat(data.getColumnIndex(WeatherEntry.COLUMN_DEGREES)); mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); // Read pressure from cursor and update view float pressure = data.getFloat(data.getColumnIndex(WeatherEntry.COLUMN_PRESSURE)); mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure)); // We still need this for the share intent mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); // If onCreateOptionsMenu has already happened, we need to update the share intent now. if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(createShareForecastIntent()); } } }