public WeatherShowInfo(WeatherInfo weatherInfo) {
   // Temperature = weatherInfo.get
   this.setTemperature(new Float(weatherInfo.getMain().getTemp()).toString());
   this.setPressure(new Float(weatherInfo.getMain().getPressure()).toString());
   this.setHumidity(new Integer(weatherInfo.getMain().getHumidity()).toString());
   this.setWind(new Float(weatherInfo.getWind().getSpeed()).toString());
   this.setMoodDay("0");
 };
Пример #2
0
 // 模拟客户端请求
 public static void main(String[] args) {
   String url = "http://10.200.105.186:8022/mobile_web/getHessian.do";
   HessianProxyFactory hessianProxyFactory = new HessianProxyFactory();
   HessianInterface hessianInterface = null;
   WeatherInfo weatherInfo = new WeatherInfo();
   try {
     hessianInterface = (HessianInterface) hessianProxyFactory.create(HessianInterface.class, url);
     weatherInfo = hessianInterface.request();
   } catch (MalformedURLException e) {
     System.out.println("occur exception: " + e);
     e
         .printStackTrace(); // To change body of catch statement use File | Settings | File
                             // Templates.
   }
   System.out.println(weatherInfo.getCity());
   System.out.println(hessianInterface.request().getPtime());
 }
Пример #3
0
 private LinkedList<WeatherInfo> collectWeatherInfo() {
   LinkedList<WeatherInfo> weatherInfos = new LinkedList<WeatherInfo>();
   for (IWeatherProvider provider : providers) {
     for (City city : cities) {
       try {
         IWeatherData data = provider.getWeatherData(city);
         WeatherInfo weatherInfo = new WeatherInfo(data);
         weatherInfo.setCityId(city.getId());
         weatherInfo.setProviderId(provider.getId());
         weatherInfos.add(weatherInfo);
       } catch (WeatherProviderException e) {
         System.out.println(
             String.format(
                 "Weather provider %s reported error: %s", provider.getId(), e.toString()));
       }
     }
   }
   return weatherInfos;
 }
Пример #4
0
  private void showWeatherUpdate(WeatherInfo winfo) {
    Date now = new Date();

    Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
    calendar.setTime(now); // assigns calendar to given date

    String day = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));
    String month = calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ITALIAN);
    String year = String.valueOf(calendar.get(Calendar.YEAR));

    String title = selectedCity + ", " + day + " " + month + " " + year;
    mDegree.setText(winfo.getDegree() + "°C");
    mTitle.setText(title);
    // mIconWeather.setImageBitmap(winfo.getIcon());

    int resID =
        getResources().getIdentifier("icon" + winfo.getCode(), "drawable", getPackageName());
    mIconWeather.setImageResource(resID);
    // Toast.makeText(this, "Using image: "+"icon"+winfo.getCode()+" ("+resID+")",
    // Toast.LENGTH_SHORT).show();
  }
Пример #5
0
  @Override
  protected String doInBackground(Location... locations) {
    Location lCityLocation = locations[0];

    // Location values in Regions class
    Region.setMyLocation_latitude(String.valueOf(lCityLocation.getLatitude()));
    Region.setMyLocation_longitude(String.valueOf(lCityLocation.getLongitude()));

    MainActivity.weatherJSONResponse = WeatherInfo.getWeatherInfo(lCityLocation);

    return MainActivity.weatherJSONResponse;
  }
Пример #6
0
    @Override
    protected ArrayList<WeatherInfo> doInBackground(Integer... integers) {

      // 以下是获取单个城市天气的十天之内的天气信息
      Document doc = null;
      // 下面是获取所有省份的信息,主要是名字和拼音
      Document doc1 = null;
      // 下面是获取一个省的所有城市的拼音和中文名字
      Document doc2 = null;
      try {
        doc = Jsoup.connect("http://tianqi.xixik.com/city/wuhan/").get();
        Elements temp = doc.getElementsByClass("oneweather");
        for (Element element : temp) {
          // System.out.println(element.text());
          WeatherInfo weatherInfo = new WeatherInfo();
          String[] t = element.text().split(" ");
          String[] te = t[3].split("~");
          weatherInfo.setTime(t[0]);
          weatherInfo.setXingqi(t[1]);
          weatherInfo.setStatus(t[2]);
          weatherInfo.setMaxDegree(te[0]);
          weatherInfo.setMinDegree(te[1]);
          weatherInfo.setWindStatus(t[4]);
          weatherInfos.add(weatherInfo);
        }
        Elements temp1 = doc.getElementsByClass("fourday");
        for (Element element : temp1) {

          WeatherInfo weatherInfo = new WeatherInfo();
          String[] t = element.text().split(" ");
          String t1 = t[0].substring(0, 6);
          String t2 = t[0].substring(6, t[0].length());
          String[] te1 = t[2].split("~");
          weatherInfo.setTime(t1);
          weatherInfo.setXingqi(t2.substring(1, t2.length() - 1));
          weatherInfo.setStatus(t[1]);
          weatherInfo.setMaxDegree(te1[0]);
          weatherInfo.setMinDegree(te1[1]);
          weatherInfo.setWindStatus(t[3]);
          weatherInfos.add(weatherInfo);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      // 获取省份信息
      try {
        doc1 = Jsoup.connect("http://tianqi.xixik.com/city/wuhan/").get();
        Elements Province = doc1.getElementsByClass("line");

        for (int i = 5; i < 12; i++) {
          // System.out.println(Province.get(i));
          String element0 = Province.get(i).text();
          String[] t2 = element0.split(" ");
          // 获取标签中的a的信息
          Elements te = Province.get(i).getElementsByTag("a");
          for (Element element : te) {
            // 将每个标签中的拼音和中文地名分别提取出来
            String linkHref = element.attr("href");
            String linkText = element.text().trim();
            ProvinceInfo provinceInfo = new ProvinceInfo();
            provinceInfo.setPinyin(linkHref);
            // System.out.println(provinceInfo.getPinyin());
            provinceInfo.setProvince(linkText);
            // System.out.println(provinceInfo.getProvince());
            provinceInfo.setBigArea(t2[0]);
            // System.out.println(provinceInfo.getBigArea());
            provinceInfos.add(provinceInfo);
          }
        }
        // System.out.println(Province.get(11).text());//5,6,7,8,9,10,11
      } catch (Exception e) {
        e.printStackTrace();
      }
      // 下面是返回全国各省的城市以及县城
      try {
        doc2 = Jsoup.connect("http://tianqi.xixik.com/list/").get();
        Elements city0 = doc2.getElementsByClass("cityline");
        for (Element element : city0) {
          Elements city = element.getElementsByTag("a");
          for (Element element1 : city) {
            String linkHref = element1.attr("href");
            // System.out.println(linkHref);
            String linkText = element1.text().trim();
            // System.out.println(linkText);
            City_County_Info city_County_Info = new City_County_Info();
            city_County_Info.setProvince(linkText);
            city_County_Info.setPinyin(linkHref);
            ci.add(city_County_Info);
          }
          // System.out.println(element.text());
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      return weatherInfos;
    }
Пример #7
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    Intent act;

    switch (item.getItemId()) {
      case R.id.menu_settings1:
        makeToast("PlayActivity is being started ...");
        act = new Intent(getBaseContext(), PlayActivity.class);
        startActivity(act);
        break;

      case R.id.listDrive:
        makeToast("listDrive...");
        act = new Intent(getBaseContext(), DriveActivity.class);
        act.putExtra("FUNCTION", "L");
        startActivity(act);
        break;

      case R.id.writeDrive:
        makeToast("writeDrive...");
        act = new Intent(getBaseContext(), DriveActivity.class);
        act.putExtra("FUNCTION", "W");
        startActivity(act);
        break;

      case R.id.readDrive:
        makeToast("writeDrive...");
        act = new Intent(getBaseContext(), DriveActivity.class);
        act.putExtra("FUNCTION", "R");
        startActivity(act);
        break;

      case R.id.postToWeb:
        makeToast("post to web...");
        act = new Intent(getBaseContext(), DriveActivity.class);
        act.putExtra("FUNCTION", "P");
        startActivity(act);
        break;

      case R.id.preferences:
        makeToast("Preferences...");
        act = new Intent(getBaseContext(), Preferences.class);
        startActivity(act);
        break;

      case R.id.dumpForecasts:
        toast = WeatherInfo.dumpForecastsToString();
        makeToast("Forecasts:\n\n" + toast);
        showDialog(DIALOG_ALERT);

        break;
      case R.id.presentForecasts:
        makeToast("presentForecasts...");
        act = new Intent(getBaseContext(), PresentForecastsActivity.class);
        startActivity(act);
        break;
      case R.id.reference1:
        makeToast("reference1...");
        act = new Intent(getBaseContext(), Ref1Activity.class);
        startActivity(act);
        break;

      case R.id.x1:
        makeToast("X1 ... ? ? ? ...");

        // DOES NOT WORK -- NPE -- listAssets();

        // String

        // String
        // url="http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false";
        //
        // String result=Utilities.callHttp(url);
        //
        // System.out.println(TAG + SPLAT + " result=" + result);
        //

        // JSONObject jsonObj = null;
        // try {
        // // jsonObj = new JSONObject(Utilities.callDirections(
        // // "40.7251,-73.9943", "40.7227,-73.9920");
        // //
        // jsonObj = Utilities.callDirections("08854", "10012");
        //
        // System.out.println(TAG + SPLAT + " result="
        // + jsonObj.toString(5));
        //
        // int meter = Utilities.directionsGetDistance(jsonObj);
        // int seconds = Utilities.directionsGetDuration(jsonObj);
        // double miles = meter * 0.00062137119;
        // System.out.println("Miles: " + miles);
        // System.out.println("seconds: " + seconds);
        // System.out.println("minutes: " + seconds/60);
        //
        // } catch (Exception e) {
        // e.printStackTrace();
        // }
        // ;

        //
        // String data = Utilities.callCityData("Camden", "New-Jersey");
        //
        // // System.out.println("data: " + data);
        //
        // String cd = Utilities.cityDataGetCrime(data);
        //
        // System.out.println(" crime data: " + cd);

        // Task.generateFieldCode(); //

        // processAssets();

        System.out.println("html=" + processFile());

        break;
    }
    return true;
  }
Пример #8
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;
  }