コード例 #1
0
ファイル: HotCityAdapter.java プロジェクト: lpjhblpj/coco4.7
  public static void update(List<String> citys) {
    selected = new boolean[citys.size()];

    Map<String, WeatherSet> data = LocalWeatherManager.loadWeatherData(context);

    Set<String> hash = new TreeSet<String>();
    if (data != null) {
      for (WeatherSet set : data.values()) {
        hash.add(set.getCityCn());
      }
    }

    for (int i = 0; i < citys.size(); i++) {
      if (hash.contains(citys.get(i))) {
        selected[i] = true;
      }
    }
  }
コード例 #2
0
ファイル: WeatherDetail.java プロジェクト: lpjhblpj/coco4.7
  @SuppressWarnings("unused")
  private void initUI() {
    ws = CalendarWeatherManager.loadWeatherData(this, city);
    int[] layouts = new int[] {R.id.day1, R.id.day2, R.id.day3, R.id.day4, R.id.day5};

    int[] topTem = new int[5];
    int[] lowTem = new int[5];

    Calendar now = Calendar.getInstance();
    now.setTime(Calendar.getInstance().getTime());
    now.set(Calendar.HOUR_OF_DAY, 0);
    now.set(Calendar.MINUTE, 0);
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 0);

    TextView tv, day, date, currentTemp, currentWind, currentPM;
    View layout;
    WeatherForecastCondition condition;
    int flag = 0;

    currentTemp = (TextView) findViewById(R.id.current_temp);
    currentWind = (TextView) findViewById(R.id.current_wind);
    currentPM = (TextView) findViewById(R.id.current_pm);

    if (ws != null && ws.getWeatherForecastConditions().size() != 0) {
      WeatherCurrentCondition wcc = ws.getWeatherCurrentCondition();
      Calendar nowTime = Calendar.getInstance();
      if (wcc != null) {
        Typeface typeface =
            Typeface.createFromAsset(WeatherDetail.this.getAssets(), "fonts/weather.ttf");
        currentTemp.setTypeface(typeface);
        currentTemp.setText(wcc.getTemperature().replace("℃", "'"));
        currentWind.setText(wcc.getWindCondition());

        if (wcc.getHasPM()) {
          String conditionDetail = wcc.getConditionDetail();
          if (conditionDetail != null
              && !conditionDetail.equals("")
              && wcc.getDate() == nowTime.getTime().getDate()) {
            currentPM.setText(getResources().getString(R.string.today_pm) + "  " + conditionDetail);
          } else {
            currentPM.setText(
                getResources().getString(R.string.today_pm)
                    + "  "
                    + getResources().getString(R.string.weather_no_data));
          }
        } else {
          currentPM.setText("");
        }
      } else {
        currentWind.setText(getResources().getString(R.string.weather_no_data));
        currentTemp.setText("");
        currentPM.setText("");
      }

      Calendar c = Calendar.getInstance();
      int size = ws.getWeatherForecastConditions().size();
      for (int i = 0; i < size; i++) {
        condition = ws.getWeatherForecastConditions().get(i);
        Calendar weatherDate = Calendar.getInstance();
        if (condition == null) {
          weatherDate.setTime(c.getTime());
        } else {
          weatherDate.setTime(condition.getDate());
        }
        weatherDate.setTime(condition.getDate());
        weatherDate.set(Calendar.HOUR_OF_DAY, 0);
        weatherDate.set(Calendar.MINUTE, 0);
        weatherDate.set(Calendar.SECOND, 0);
        weatherDate.set(Calendar.MILLISECOND, 0);

        int dayIndex =
            (int) ((weatherDate.getTimeInMillis() - now.getTimeInMillis()) / (24 * 60 * 60 * 1000));
        if (dayIndex >= 0 && dayIndex < 5) {
          flag++;
          layout = findViewById(layouts[dayIndex]);
          day = (TextView) layout.findViewById(R.id.day);
          date = (TextView) layout.findViewById(R.id.date);

          if (dayIndex == 0) {
            day.setText(getString(R.string.jintian));
            day.setTextColor(Color.parseColor("#ffd200"));
            date.setText(
                (weatherDate.get(Calendar.MONTH) + 1)
                    + "/"
                    + DataFormatManager.Pad(weatherDate.get(Calendar.DAY_OF_MONTH)));
          } else if (dayIndex == 1) {
            day.setText(getString(R.string.mingtian));
            date.setText(
                (weatherDate.get(Calendar.MONTH) + 1)
                    + "/"
                    + DataFormatManager.Pad(weatherDate.get(Calendar.DAY_OF_MONTH)));
          } else {
            if (condition != null) {
              day.setText(condition.getDayofWeek());
            } else {
              day.setText(c.get(Calendar.DAY_OF_WEEK));
            }
            date.setText(
                (weatherDate.get(Calendar.MONTH) + 1)
                    + "/"
                    + DataFormatManager.Pad(weatherDate.get(Calendar.DAY_OF_MONTH)));
          }

          c.add(Calendar.DAY_OF_MONTH, 1);
          if (condition == null || condition.equals("")) {
            return;
          }

          String[] winds = new String[0];
          String windStr = condition.getWindCondition();
          int index;
          if (windStr != null && !windStr.equals("")) {
            if (windStr.contains("-")
                && windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf("-") < windStr.indexOf(getString(R.string.zhuan))) {
              index = windStr.lastIndexOf(getString(R.string.zhuan));
              winds = windStr.substring(0, index).split("-");
            } else if (windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.less_than))
                    < windStr.indexOf(getString(R.string.zhuan))) {
              index = windStr.lastIndexOf(getString(R.string.zhuan));
              winds = windStr.substring(0, index).split(getString(R.string.less_than));
            } else if (windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.less_than))) {
              winds = windStr.split(getString(R.string.less_than));
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.greater_than))
                    < windStr.indexOf(getString(R.string.zhuan))) {
              index = windStr.lastIndexOf(getString(R.string.zhuan));
              winds = windStr.substring(0, index).split(getString(R.string.greater_than));
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.greater_than))) {
              winds = windStr.split(getString(R.string.greater_than));
            } else if (windStr.contains("-")
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf("-") < windStr.indexOf(getString(R.string.zhuan))) {
              index = windStr.lastIndexOf(getString(R.string.zhuan));
              winds = windStr.substring(0, index).split("-");
            } else if (windStr.contains("-")
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan)) < windStr.indexOf("-")) {
              winds = windStr.split("-");
            } else if (windStr.contains(getString(R.string.less_than))) {
              winds = windStr.split(getString(R.string.less_than));
            } else if (windStr.contains(getString(R.string.greater_than))) {
              winds = windStr.split(getString(R.string.greater_than));
            } else if (windStr.contains("-")) {
              winds = windStr.split("-");
            } else {
              winds = windStr.split(" ");
            }
          }

          tv = (TextView) layout.findViewById(R.id.wind);
          String windString;
          if (winds.length > 0 && windStr != null && !windStr.equals("")) {
            if (windStr.contains("-")
                && windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf("-") < windStr.indexOf(getString(R.string.zhuan))) {
              windString = winds[0].substring(0, winds[0].length() - 1);
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.less_than))
                    < windStr.indexOf(getString(R.string.zhuan))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);

            } else if (windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.less_than))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.greater_than))
                    < windStr.indexOf(getString(R.string.zhuan))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.greater_than))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.greater_than))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains("-")
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf("-") < windStr.indexOf(getString(R.string.zhuan))) {
              windString = winds[0].substring(0, winds[0].length() - 1);
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains("-")
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan)) < windStr.indexOf("-")) {
              windString = winds[0].substring(0, winds[0].length() - 1);
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains(getString(R.string.less_than))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains(getString(R.string.greater_than))) {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else if (windStr.contains("-")) {
              windString = winds[0].substring(0, winds[0].length() - 1);
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            } else {
              windString = winds[0];
              if (windString.contains(getString(R.string.zhuan))) {
                index = windString.lastIndexOf(getString(R.string.zhuan));
                windString = windString.substring(0, index);
              }
              tv.setText(windString);
            }

          } else {
            tv.setText(getString(R.string.weather_no_data));
          }
          tv = (TextView) layout.findViewById(R.id.wind_force);

          if (winds.length > 1 && windStr != null && !windStr.equals("")) {
            if (windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.less_than))
                    < windStr.indexOf(getString(R.string.zhuan))) {
              tv.setText("<" + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains(getString(R.string.less_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.less_than))) {
              tv.setText("<" + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.greater_than))
                    < windStr.indexOf(getString(R.string.zhuan))) {
              tv.setText(">" + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains(getString(R.string.greater_than))
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan))
                    < windStr.indexOf(getString(R.string.greater_than))) {
              tv.setText(">" + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains("-")
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf("-") < windStr.indexOf(getString(R.string.zhuan))) {
              tv.setText(
                  winds[0].substring(winds[0].length() - 1)
                      + "-"
                      + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains("-")
                && windStr.contains(getString(R.string.zhuan))
                && windStr.indexOf(getString(R.string.zhuan)) < windStr.indexOf("-")) {
              tv.setText(
                  winds[0].substring(winds[0].length() - 1)
                      + "-"
                      + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains(getString(R.string.less_than))) {
              tv.setText("<" + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains(getString(R.string.greater_than))) {
              tv.setText(">" + winds[1].replace(getString(R.string.level), ""));
            } else if (windStr.contains("-")) {
              tv.setText(
                  winds[0].substring(winds[0].length() - 1)
                      + "-"
                      + winds[1].replace(getString(R.string.level), ""));
            } else {
              tv.setText(winds[1].replace(getString(R.string.level), ""));
            }

          } else if (winds.length > 0) {
            if (winds[0].equals(getString(R.string.no_wind))) {
              tv.setText("0");
            } else if (winds[0].equals(getString(R.string.breeze))) {
              tv.setText("<3");
            } else {
              tv.setText("<3");
            }
          } else {
            tv.setText(R.string.weather_no);
          }

          tv = (TextView) layout.findViewById(R.id.condition);

          tv.setText(condition.getCondition());

          ImageView iv;
          iv = (ImageView) layout.findViewById(R.id.img);
          iv.setImageResource(
              CalendarWeatherManager.getIconId(Integer.parseInt(condition.getIconName())));

          String[] temp = null;
          if (condition.getTemperature().contains("~")) {
            temp = condition.getTemperature().split("~");
          }

          if (temp != null && temp.length > 1) {
            int a = Integer.parseInt(temp[0].replace("℃", ""));
            int b = Integer.parseInt(temp[1].replace("℃", ""));
            topTem[dayIndex] = Math.max(a, b);
            lowTem[dayIndex] = Math.min(a, b);
          } else {
            topTem[dayIndex] = Math.max(0, 10);
            lowTem[dayIndex] = Math.min(0, 10);
          }

          TrendView trendView = (TrendView) findViewById(R.id.trend);
          trendView.setTem(topTem, lowTem);
        } else if (dayIndex < 0) {
          dayIndex = -dayIndex;

          if (dayIndex < 5) {
            topTem[i] = Math.max(0, 0);
            lowTem[i] = Math.min(0, 0);
            TrendView trendView = (TrendView) findViewById(R.id.trend);
            trendView.setTem(topTem, lowTem);
          }
        }
      }
      RelativeLayout noWeather = (RelativeLayout) findViewById(R.id.no_weather);

      if (flag < 5) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, flag);
        for (int j = 0; j < 5 - flag; j++) {
          layout = findViewById(layouts[flag + j]);
          day = (TextView) layout.findViewById(R.id.day);
          date = (TextView) layout.findViewById(R.id.date);
          day.setText(DataFormatManager.DayOfWeekDisplay(calendar.get(Calendar.DAY_OF_WEEK)));
          date.setText(
              (calendar.get(Calendar.MONTH) + 1)
                  + "/"
                  + DataFormatManager.Pad(calendar.get(Calendar.DAY_OF_MONTH)));
          calendar.add(Calendar.DAY_OF_MONTH, 1);

          conditionText = (TextView) layout.findViewById(R.id.condition);
          wind_force = (TextView) layout.findViewById(R.id.wind_force);
          wind = (TextView) layout.findViewById(R.id.wind);
          conditionText.setText("");
          wind_force.setText("");
          wind.setText(getString(R.string.weather_no));

          ImageView iv = (ImageView) layout.findViewById(R.id.img);
          iv.setImageResource(Color.TRANSPARENT);
        }

        if (flag < 6) {
          int width = getResources().getDisplayMetrics().widthPixels / 5;
          RelativeLayout.LayoutParams params =
              new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
          params.width = width * (5 - flag);
          params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
          params.setMargins(0, 0, 0, 100);
          noWeather.setLayoutParams(params);
        }

        noWeather.setVisibility(View.GONE);
      } else {
        noWeather.setVisibility(View.GONE);
      }
    }
  }
コード例 #3
0
ファイル: WeatherDetail.java プロジェクト: lpjhblpj/coco4.7
  /**
   * NULLPointerException at com.when.coco.weather.WeatherDetail.releaseTime(WeatherDetail.java:471)
   * at com.when.coco.weather.WeatherDetail.updateWeatherData(WeatherDetail.java:421) at
   * com.when.coco.weather.WeatherDetail.onCreate(WeatherDetail.java:76)
   */
  @SuppressLint("SimpleDateFormat")
  private Date releaseTime() {
    Date date = new Date(Long.parseLong(ws.getForecast_date()) * 1000);

    return date;
  }