Exemplo n.º 1
0
  @Override
  public void bindView(View view, Context context, Cursor cursor) {

    ViewHolder viewHolder = (ViewHolder) view.getTag();

    // Read weather icon ID from cursor
    int weatherId = cursor.getInt(ForecastFragment.COL_WEATHER_ID);
    String dateString = cursor.getString(ForecastFragment.COL_WEATHER_DATE);
    String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC);
    boolean isMetric = Utility.isMetric(context);
    float high = cursor.getFloat(ForecastFragment.COL_WEATHER_MAX_TEMP);
    float low = cursor.getFloat(ForecastFragment.COL_WEATHER_MIN_TEMP);

    //        viewHolder.iconView.setImageResource(R.mipmap.ic_launcher);
    viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateString));
    viewHolder.descriptionView.setText(description);

    viewHolder.highTempView.setText(Utility.formatTemperature(context, high, isMetric));
    viewHolder.lowTempView.setText(Utility.formatTemperature(context, low, isMetric));

    if (getItemViewType(cursor.getPosition()) == VIEW_TYPE_TODAY) {
      int artResource =
          Utility.getArtResourceForWeatherCondition(
              cursor.getInt(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID)));
      viewHolder.iconView.setImageResource(artResource);
    } else {
      int iconResource =
          Utility.getIconResourceForWeatherCondition(
              cursor.getInt(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID)));
      viewHolder.iconView.setImageResource(iconResource);
    }
  }
Exemplo n.º 2
0
  @Override
  public void bindView(View view, Context context, Cursor cursor) {

    ViewHolder viewHolder = (ViewHolder) view.getTag();

    int viewType = getItemViewType(cursor.getPosition());
    switch (viewType) {
      case VIEW_TYPE_TODAY:
        viewHolder.iconView.setImageResource(
            Utility.getArtResourceForWeatherCondition(
                cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID)));
        break;
      case VIEW_TYPE_FUTURE_DAY:
        viewHolder.iconView.setImageResource(
            Utility.getIconResourceForWeatherCondition(
                cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID)));
        break;
    }

    // Read date from cursor
    long dateInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE);
    // Find TextView and set formatted date on it
    viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis));

    // Read weather forecast from cursor
    String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC);

    // Find TextView and set weather forecast on it.
    viewHolder.descriptionView.setText(description);

    // For accessibility, add a content description to the icon field
    viewHolder.iconView.setContentDescription(description);

    // Read user preference for metric or imperial temperature units
    boolean isMetric = Utility.isMetric(context);

    // Read high temperature from cursor
    double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP);
    viewHolder.highTempView.setText(Utility.formatTemperature(context, high));

    // Read low temperature from cursor
    double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP);
    viewHolder.lowTempView.setText(Utility.formatTemperature(context, low));
  }