Esempio n. 1
0
 private void parseForecastInfo(
     final ForecastInfo forecastInfo, final Document doc, final int index) {
   Node forecast1ConditionNode = doc.getElementsByTagName("yweather:forecast").item(index);
   forecastInfo.setForecastCode(
       Integer.parseInt(
           forecast1ConditionNode.getAttributes().getNamedItem("code").getNodeValue()));
   forecastInfo.setForecastText(
       forecast1ConditionNode.getAttributes().getNamedItem("text").getNodeValue());
   forecastInfo.setForecastDate(
       forecast1ConditionNode.getAttributes().getNamedItem("date").getNodeValue());
   forecastInfo.setForecastDay(
       forecast1ConditionNode.getAttributes().getNamedItem("day").getNodeValue());
   forecastInfo.setForecastTempHighF(
       Integer.parseInt(
           forecast1ConditionNode.getAttributes().getNamedItem("high").getNodeValue()));
   forecastInfo.setForecastTempLowF(
       Integer.parseInt(
           forecast1ConditionNode.getAttributes().getNamedItem("low").getNodeValue()));
   if (mNeedDownloadIcons) {
     forecastInfo.setForecastConditionIcon(
         ImageUtils.getBitmapFromWeb(forecastInfo.getForecastConditionIconURL()));
   }
 }
Esempio n. 2
0
  private WeatherInfo parseWeatherInfo(Context context, Document doc, WOEIDInfo woeidInfo) {
    WeatherInfo weatherInfo = new WeatherInfo();
    try {

      Node titleNode = doc.getElementsByTagName("title").item(0);

      if (titleNode.getTextContent().equals(YAHOO_WEATHER_ERROR)) {
        return null;
      }

      weatherInfo.setTitle(titleNode.getTextContent());
      weatherInfo.setDescription(doc.getElementsByTagName("description").item(0).getTextContent());
      weatherInfo.setLanguage(doc.getElementsByTagName("language").item(0).getTextContent());
      weatherInfo.setLastBuildDate(
          doc.getElementsByTagName("lastBuildDate").item(0).getTextContent());

      Node locationNode = doc.getElementsByTagName("yweather:location").item(0);
      weatherInfo.setLocationCity(locationNode.getAttributes().getNamedItem("city").getNodeValue());
      weatherInfo.setLocationRegion(
          locationNode.getAttributes().getNamedItem("region").getNodeValue());
      weatherInfo.setLocationCountry(
          locationNode.getAttributes().getNamedItem("country").getNodeValue());

      Node windNode = doc.getElementsByTagName("yweather:wind").item(0);
      weatherInfo.setWindChill(windNode.getAttributes().getNamedItem("chill").getNodeValue());
      weatherInfo.setWindDirection(
          windNode.getAttributes().getNamedItem("direction").getNodeValue());
      weatherInfo.setWindSpeed(windNode.getAttributes().getNamedItem("speed").getNodeValue());

      Node atmosphereNode = doc.getElementsByTagName("yweather:atmosphere").item(0);
      weatherInfo.setAtmosphereHumidity(
          atmosphereNode.getAttributes().getNamedItem("humidity").getNodeValue());
      weatherInfo.setAtmosphereVisibility(
          atmosphereNode.getAttributes().getNamedItem("visibility").getNodeValue());
      weatherInfo.setAtmospherePressure(
          atmosphereNode.getAttributes().getNamedItem("pressure").getNodeValue());
      weatherInfo.setAtmosphereRising(
          atmosphereNode.getAttributes().getNamedItem("rising").getNodeValue());

      Node astronomyNode = doc.getElementsByTagName("yweather:astronomy").item(0);
      weatherInfo.setAstronomySunrise(
          astronomyNode.getAttributes().getNamedItem("sunrise").getNodeValue());
      weatherInfo.setAstronomySunset(
          astronomyNode.getAttributes().getNamedItem("sunset").getNodeValue());

      weatherInfo.setConditionTitle(doc.getElementsByTagName("title").item(2).getTextContent());
      weatherInfo.setConditionLat(doc.getElementsByTagName("geo:lat").item(0).getTextContent());
      weatherInfo.setConditionLon(doc.getElementsByTagName("geo:long").item(0).getTextContent());

      Node currentConditionNode = doc.getElementsByTagName("yweather:condition").item(0);
      weatherInfo.setCurrentCode(
          Integer.parseInt(
              currentConditionNode.getAttributes().getNamedItem("code").getNodeValue()));
      weatherInfo.setCurrentText(
          currentConditionNode.getAttributes().getNamedItem("text").getNodeValue());
      weatherInfo.setCurrentTempF(
          Integer.parseInt(
              currentConditionNode.getAttributes().getNamedItem("temp").getNodeValue()));
      weatherInfo.setCurrentConditionDate(
          currentConditionNode.getAttributes().getNamedItem("date").getNodeValue());

      if (mNeedDownloadIcons) {
        weatherInfo.setCurrentConditionIcon(
            ImageUtils.getBitmapFromWeb(weatherInfo.getCurrentConditionIconURL()));
      }

      for (int i = 0; i < FORECAST_INFO_MAX_SIZE; i++) {
        this.parseForecastInfo(weatherInfo.getForecastInfoList().get(i), doc, i);
      }

      /*
       * pass some woied info
       */
      weatherInfo.mWOEIDneighborhood = woeidInfo.mNeighborhood;
      weatherInfo.mWOEIDCounty = woeidInfo.mCounty;
      weatherInfo.mWOEIDState = woeidInfo.mState;
      weatherInfo.mWOEIDCountry = woeidInfo.mCountry;

    } catch (NullPointerException e) {
      YahooWeatherLog.printStack(e);
      if (mExceptionListener != null) mExceptionListener.onFailParsing(e);
      weatherInfo = null;
    }

    return weatherInfo;
  }