Exemplo n.º 1
0
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data != null && data.moveToFirst()) {
      // Read weather condition ID from cursor
      int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);

      // Use weather art image
      mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));

      // Read date from cursor and update views for day of week and date
      long date = data.getLong(COL_WEATHER_DATE);
      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(COL_WEATHER_DESC);
      mDescriptionView.setText(description);

      // Read high temperature from cursor and update view
      boolean isMetric = Utility.isMetric(getActivity());

      double high = data.getDouble(COL_WEATHER_MAX_TEMP);
      String highString = Utility.formatTemperature(getActivity(), high);
      mHighTempView.setText(highString);

      // Read low temperature from cursor and update view
      double low = data.getDouble(COL_WEATHER_MIN_TEMP);
      String lowString = Utility.formatTemperature(getActivity(), low);
      mLowTempView.setText(lowString);

      // Read humidity from cursor and update view
      float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
      mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));

      // Read wind speed and direction from cursor and update view
      float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
      float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
      mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

      // Read pressure from cursor and update view
      float pressure = data.getFloat(COL_WEATHER_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());
      }
    }
  }
Exemplo n.º 2
0
  public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor data) {

    if (!data.moveToFirst() || data == null) return;

    int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
    // mIconView.setImageResource(R.drawable.ic_launcher);
    mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));

    long date = data.getLong(COL_WEATHER_DATE);
    String friendlyDateText = Utility.getDayName(getActivity(), date);
    String dateText = Utility.getFormattedMonthDay(getActivity(), date);
    mFriendlyDateView.setText(friendlyDateText);
    mDateView.setText(dateText);

    String description = data.getString(COL_WEATHER_DESC);
    mDescriptionView.setText(description);

    boolean isMetric = Utility.isMetric(getActivity());
    double high = data.getDouble(COL_WEATHER_MAX_TEMP);
    String highString = Utility.formatTemperature(getActivity(), high, isMetric);
    mHighTempView.setText(highString);

    double low = data.getDouble(COL_WEATHER_MIN_TEMP);
    String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
    mLowTempView.setText(lowString);

    float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
    mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));

    float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
    float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
    mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

    float pressure = data.getFloat(COL_WEATHER_PRESSURE);
    mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure));

    mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low);

    if (mShareActionProvider != null) {
      mShareActionProvider.setShareIntent(createShareForecastIntent());
    }
  }
  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    /*Log.v(LOG_TAG, "In onLoadFinished");
    if (!data.moveToFirst()) {
        return;
    }

    String date = Utility.formatDate(data.getLong(COL_WEATHER_DATE));
    String desc = data.getString(COL_WEATHER_DESC);
    Boolean ismetric = Utility.isMetric(getActivity());
    String max = Utility.formatTemperature(getActivity(), data.getDouble(COL_WEATHER_MAX_TEMP), ismetric);
    String min = Utility.formatTemperature(getActivity(), data.getDouble(COL_WEATHER_MIN_TEMP), ismetric);

    mForecast = String.format("%s - %s %s-%s", date, desc, max, min);

    TextView tv = (TextView) getView().findViewById(R.id.detail_text);
    tv.setText(mForecast);

    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(createShareForecastIntent());
    }*/

    Log.v(LOG_TAG, "In onLoadFinished");
    if (data != null && data.moveToFirst()) {
      // Read weather condition ID from cursor
      int weatherId = data.getInt(COL_WEATHER_CONDITION_ID);
      // Use placeholder Image
      // mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId));
      Glide.with(this)
          .load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId))
          .error(Utility.getArtResourceForWeatherCondition(weatherId))
          .crossFade()
          .into(mIconView);

      // Read date from cursor and update views for day of week and date
      long date = data.getLong(COL_WEATHER_DATE);
      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(COL_WEATHER_DESC);
      mDescriptionView.setText(description);

      // Read high temperature from cursor and update view
      boolean isMetric = Utility.isMetric(getActivity());

      double high = data.getDouble(COL_WEATHER_MAX_TEMP);
      String highString = Utility.formatTemperature(getActivity(), high, isMetric);
      mHighTempView.setText(highString);

      // Read low temperature from cursor and update view
      double low = data.getDouble(COL_WEATHER_MIN_TEMP);
      String lowString = Utility.formatTemperature(getActivity(), low, isMetric);
      mLowTempView.setText(lowString);

      // Read humidity from cursor and update view
      float humidity = data.getFloat(COL_WEATHER_HUMIDITY);
      mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity));

      // Read wind speed and direction from cursor and update view
      float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
      float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
      mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));

      // Read pressure from cursor and update view
      float pressure = data.getFloat(COL_WEATHER_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());
      }
    }
  }