diff --git a/app/build.gradle b/app/build.gradle index b026db7..e364680 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.odiousapps.weewxweather" minSdkVersion 19 targetSdkVersion 28 - versionCode 6002 - versionName "0.6.2" + versionCode 6003 + versionName "0.6.3" } buildTypes { release { diff --git a/app/src/main/java/com/odiousapps/weewxweather/Common.java b/app/src/main/java/com/odiousapps/weewxweather/Common.java index 15aee40..066e196 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Common.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Common.java @@ -21,6 +21,7 @@ import android.widget.RemoteViews; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; @@ -321,6 +322,97 @@ RemoteViews buildUpdate(Context context) return views; } + String[] processWMO(String data) + { + return processWMO(data, false); + } + + String[] processWMO(String data, boolean showHeader) + { + if(data == null || data.equals("")) + return null; + + String desc = ""; + StringBuilder out = new StringBuilder(); + boolean metric = GetBoolPref("metric", true); + + try + { + JSONObject jobj = new JSONObject(data); + + desc = jobj.getJSONObject("city").getString("cityName") + ", " + jobj.getJSONObject("city").getJSONObject("member").getString("memName"); + String tmp = jobj.getJSONObject("city").getJSONObject("forecast").getString("issueDate"); + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + long mdate = sdf.parse(tmp).getTime(); + sdf = new SimpleDateFormat("dd MMM yyyy HH:mm", Locale.getDefault()); + String date = sdf.format(mdate); + + tmp = "
" + date + "
"; + out.append(tmp); + tmp = "\n"; + out.append(tmp); + + JSONArray jarr = jobj.getJSONObject("city").getJSONObject("forecast").getJSONArray("forecastDay"); + for(int i = 0; i < jarr.length(); i++) + { + JSONObject j = jarr.getJSONObject(i); + + date = j.getString("forecastDate").trim(); + sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); + mdate = sdf.parse(date).getTime(); + sdf = new SimpleDateFormat("EEEE", Locale.getDefault()); + date = sdf.format(mdate); + + String text = j.getString("weather"); + String max = j.getString("maxTemp") + "°C"; + String min = j.getString("minTemp") + "°C"; + if(!metric) + { + max = j.getString("maxTempF") + "°F"; + min = j.getString("minTempF") + "°F"; + } + + String code = j.getString("weatherIcon"); + code = code.substring(0, 2); + + tmp = ""; + out.append(tmp); + + tmp = ""; + out.append(tmp); + + if(!max.equals("")) + tmp = ""; + else + tmp = ""; + out.append(tmp); + + tmp = ""; + out.append(tmp); + + if(!min.equals("")) + tmp = ""; + else + tmp = ""; + out.append(tmp); + + if(showHeader) + { + tmp = ""; + out.append(tmp); + } + } + + out.append("
" + "" + date + "" + max + "
 
" + text + "" + min + "
 
 
"); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + + return new String[]{out.toString(), desc}; + } + String[] processBOM(String data) { return processBOM(data, false); @@ -337,7 +429,7 @@ String[] processBOM(String data, boolean showHeader) try { JSONObject jobj = new JSONObject(data); - desc = jobj.getString("description"); + desc = jobj.getString("description") + ", Australia"; String tmp = jobj.getString("content"); tmp = tmp.substring(0, tmp.length() - 6); @@ -368,16 +460,22 @@ String[] processBOM(String data, boolean showHeader) } } - for(int x = 0; x < j.getJSONArray("element").length(); x++) + try { - if(j.getJSONArray("element").getJSONObject(x).getString("type").equals("forecast_icon_code")) - code = j.getJSONArray("element").getJSONObject(x).getString("content"); + JSONArray jarr2 = j.getJSONArray("element"); + for (int x = 0; x < jarr2.length(); x++) + { + if (jarr2.getJSONObject(x).getString("type").equals("forecast_icon_code")) + code = jarr2.getJSONObject(x).getString("content"); - if(j.getJSONArray("element").getJSONObject(x).getString("type").equals("air_temperature_minimum")) - min = j.getJSONArray("element").getJSONObject(x).getString("content"); + if (jarr2.getJSONObject(x).getString("type").equals("air_temperature_minimum")) + min = jarr2.getJSONObject(x).getString("content"); - if(j.getJSONArray("element").getJSONObject(x).getString("type").equals("air_temperature_maximum")) - max = j.getJSONArray("element").getJSONObject(x).getString("content"); + if (jarr2.getJSONObject(x).getString("type").equals("air_temperature_maximum")) + max = jarr2.getJSONObject(x).getString("content"); + } + } catch (JSONException e) { + code = j.getJSONObject("element").getString("content"); } date = j.getString("start-time-local").trim(); diff --git a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java index 55bcea8..6f85bd3 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Forecast.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Forecast.java @@ -23,6 +23,9 @@ import com.github.rongi.rotate_layout.layout.RotateLayout; +import org.json.JSONArray; +import org.json.JSONObject; + import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -32,6 +35,8 @@ import java.net.URL; import java.net.URLConnection; +import fr.arnaudguyon.xmltojsonlib.XmlToJson; + class Forecast { private Common common; @@ -492,9 +497,36 @@ public void run() } in.close(); + String tmp = sb.toString().trim(); + if(common.GetStringPref("fctype", "Yahoo").equals("bom.gov.au")) + { + try + { + JSONObject jobj = new XmlToJson.Builder(tmp).build().toJson(); + if(jobj == null) + return; + + jobj = jobj.getJSONObject("product"); + String content = jobj.getJSONObject("amoc").getJSONObject("issue-time-local").getString("content"); + JSONArray area = jobj.getJSONObject("forecast").getJSONArray("area"); + for (int i = 0; i < area.length(); i++) + { + JSONObject o = area.getJSONObject(i); + if (o.getString("description").equals(common.GetStringPref("bomtown", ""))) + { + o.put("content", content); + tmp = o.toString(); + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Common.LogMessage("updating rss cache"); common.SetIntPref("rssCheck", curtime); - common.SetStringPref("forecastData", sb.toString().trim()); + common.SetStringPref("forecastData", tmp); } } catch (Exception e) { e.printStackTrace(); @@ -573,6 +605,13 @@ private void generateForecast() updateForecast(content[0], content[1]); break; } + case "wmo.int": + { + String[] content = common.processWMO(data, true); + if(content != null && content.length >= 2) + updateForecast(content[0], content[1]); + break; + } } } @@ -606,6 +645,9 @@ public void run() case "bom.gov.au": im.setImageResource(R.drawable.bom); break; + case "wmo.int": + im.setImageResource(R.drawable.wmo); + break; } } } \ No newline at end of file diff --git a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java index eb6eca2..c6b4158 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java +++ b/app/src/main/java/com/odiousapps/weewxweather/MainActivity.java @@ -305,7 +305,8 @@ public void onFocusChange(View v, boolean hasFocus) "Weather Icons from FlatIcon and " + "is licensed under CC 3.0 BY

" + "Forecasts supplied by Yahoo!, weatherzone and " + - "yr.no

" + + "yr.no" + + "Bureau of Meteorology

" + "weeWX Weather App v" + common.getAppversion() + " is by OdiousApps."; tv.setText(Html.fromHtml(lines)); @@ -679,6 +680,11 @@ protected PasswordAuthentication getPasswordAuthentication() Common.LogMessage("fctype=" + fctype); Common.LogMessage("bomtown=" + bomtown); break; + case "wmo.int": + forecast = "https://worldweather.wmo.int/en/json/" + forecast.trim() + "_en.xml"; + Common.LogMessage("forecast=" + forecast); + Common.LogMessage("fctype=" + fctype); + break; default: common.SetStringPref("lastError", "forecast type " + fctype + " is invalid, check your settings file and try again."); handlerForecast.sendEmptyMessage(0); @@ -717,6 +723,8 @@ protected PasswordAuthentication getPasswordAuthentication() } in.close(); + boolean found = false; + String tmp = sb.toString().trim(); if(fctype.equals("bom.gov.au")) { @@ -730,9 +738,17 @@ protected PasswordAuthentication getPasswordAuthentication() { o.put("content", content); tmp = o.toString(); + found = true; break; } } + + if(!found) + { + common.SetStringPref("lastError", "Unable to match '" + common.GetStringPref("bomtown", "") + "'. Make sure you selected the right state file ID and a town where the BoM produces forecasts."); + handlerForecast.sendEmptyMessage(0); + return; + } } Common.LogMessage("updating rss cache"); diff --git a/app/src/main/java/com/odiousapps/weewxweather/Weather.java b/app/src/main/java/com/odiousapps/weewxweather/Weather.java index bcdedd1..eb220d5 100644 --- a/app/src/main/java/com/odiousapps/weewxweather/Weather.java +++ b/app/src/main/java/com/odiousapps/weewxweather/Weather.java @@ -403,6 +403,25 @@ public void run() }); break; } + case "wmo.int": + { + String[] content = common.processWMO(data); + if(content == null || content.length <= 0) + return; + + String wmo = "
"; + final String fc = "" + wmo + content[0] + ""; + + wv.post(new Runnable() + { + @Override + public void run() + { + wv.loadDataWithBaseURL("file:///android_res/drawable/", fc, "text/html", "utf-8", null); + } + }); + break; + } } } } diff --git a/app/src/main/res/drawable/i01.png b/app/src/main/res/drawable/i01.png new file mode 100644 index 0000000..77c6178 Binary files /dev/null and b/app/src/main/res/drawable/i01.png differ diff --git a/app/src/main/res/drawable/i02.png b/app/src/main/res/drawable/i02.png new file mode 100644 index 0000000..c764b27 Binary files /dev/null and b/app/src/main/res/drawable/i02.png differ diff --git a/app/src/main/res/drawable/i03.png b/app/src/main/res/drawable/i03.png new file mode 100644 index 0000000..0c64058 Binary files /dev/null and b/app/src/main/res/drawable/i03.png differ diff --git a/app/src/main/res/drawable/i04.png b/app/src/main/res/drawable/i04.png new file mode 100644 index 0000000..0c8aa1e Binary files /dev/null and b/app/src/main/res/drawable/i04.png differ diff --git a/app/src/main/res/drawable/i05.png b/app/src/main/res/drawable/i05.png new file mode 100644 index 0000000..9ff6bef Binary files /dev/null and b/app/src/main/res/drawable/i05.png differ diff --git a/app/src/main/res/drawable/i06.png b/app/src/main/res/drawable/i06.png new file mode 100644 index 0000000..33653b7 Binary files /dev/null and b/app/src/main/res/drawable/i06.png differ diff --git a/app/src/main/res/drawable/i07.png b/app/src/main/res/drawable/i07.png new file mode 100644 index 0000000..508efdf Binary files /dev/null and b/app/src/main/res/drawable/i07.png differ diff --git a/app/src/main/res/drawable/i08.png b/app/src/main/res/drawable/i08.png new file mode 100644 index 0000000..9871c24 Binary files /dev/null and b/app/src/main/res/drawable/i08.png differ diff --git a/app/src/main/res/drawable/i09.png b/app/src/main/res/drawable/i09.png new file mode 100644 index 0000000..450db6d Binary files /dev/null and b/app/src/main/res/drawable/i09.png differ diff --git a/app/src/main/res/drawable/i10.png b/app/src/main/res/drawable/i10.png new file mode 100644 index 0000000..5af2342 Binary files /dev/null and b/app/src/main/res/drawable/i10.png differ diff --git a/app/src/main/res/drawable/i11.png b/app/src/main/res/drawable/i11.png new file mode 100644 index 0000000..caf1b4c Binary files /dev/null and b/app/src/main/res/drawable/i11.png differ diff --git a/app/src/main/res/drawable/i12.png b/app/src/main/res/drawable/i12.png new file mode 100644 index 0000000..45bbfbb Binary files /dev/null and b/app/src/main/res/drawable/i12.png differ diff --git a/app/src/main/res/drawable/i13.png b/app/src/main/res/drawable/i13.png new file mode 100644 index 0000000..236be47 Binary files /dev/null and b/app/src/main/res/drawable/i13.png differ diff --git a/app/src/main/res/drawable/i14.png b/app/src/main/res/drawable/i14.png new file mode 100644 index 0000000..2942d26 Binary files /dev/null and b/app/src/main/res/drawable/i14.png differ diff --git a/app/src/main/res/drawable/i15.png b/app/src/main/res/drawable/i15.png new file mode 100644 index 0000000..2bb8417 Binary files /dev/null and b/app/src/main/res/drawable/i15.png differ diff --git a/app/src/main/res/drawable/i16.png b/app/src/main/res/drawable/i16.png new file mode 100644 index 0000000..e0a4497 Binary files /dev/null and b/app/src/main/res/drawable/i16.png differ diff --git a/app/src/main/res/drawable/i17.png b/app/src/main/res/drawable/i17.png new file mode 100644 index 0000000..798934f Binary files /dev/null and b/app/src/main/res/drawable/i17.png differ diff --git a/app/src/main/res/drawable/i18.png b/app/src/main/res/drawable/i18.png new file mode 100644 index 0000000..78d4e48 Binary files /dev/null and b/app/src/main/res/drawable/i18.png differ diff --git a/app/src/main/res/drawable/i19.png b/app/src/main/res/drawable/i19.png new file mode 100644 index 0000000..cf6d4d5 Binary files /dev/null and b/app/src/main/res/drawable/i19.png differ diff --git a/app/src/main/res/drawable/i20.png b/app/src/main/res/drawable/i20.png new file mode 100644 index 0000000..edff7ff Binary files /dev/null and b/app/src/main/res/drawable/i20.png differ diff --git a/app/src/main/res/drawable/i21.png b/app/src/main/res/drawable/i21.png new file mode 100644 index 0000000..a486678 Binary files /dev/null and b/app/src/main/res/drawable/i21.png differ diff --git a/app/src/main/res/drawable/i21a.png b/app/src/main/res/drawable/i21a.png new file mode 100644 index 0000000..80f2d28 Binary files /dev/null and b/app/src/main/res/drawable/i21a.png differ diff --git a/app/src/main/res/drawable/i21b.png b/app/src/main/res/drawable/i21b.png new file mode 100644 index 0000000..2c9fd95 Binary files /dev/null and b/app/src/main/res/drawable/i21b.png differ diff --git a/app/src/main/res/drawable/i22.png b/app/src/main/res/drawable/i22.png new file mode 100644 index 0000000..a4031fb Binary files /dev/null and b/app/src/main/res/drawable/i22.png differ diff --git a/app/src/main/res/drawable/i22a.png b/app/src/main/res/drawable/i22a.png new file mode 100644 index 0000000..7d7c6ce Binary files /dev/null and b/app/src/main/res/drawable/i22a.png differ diff --git a/app/src/main/res/drawable/i22b.png b/app/src/main/res/drawable/i22b.png new file mode 100644 index 0000000..2a07691 Binary files /dev/null and b/app/src/main/res/drawable/i22b.png differ diff --git a/app/src/main/res/drawable/i23.png b/app/src/main/res/drawable/i23.png new file mode 100644 index 0000000..d1cb45b Binary files /dev/null and b/app/src/main/res/drawable/i23.png differ diff --git a/app/src/main/res/drawable/i23a.png b/app/src/main/res/drawable/i23a.png new file mode 100644 index 0000000..05b571c Binary files /dev/null and b/app/src/main/res/drawable/i23a.png differ diff --git a/app/src/main/res/drawable/i23b.png b/app/src/main/res/drawable/i23b.png new file mode 100644 index 0000000..74411e4 Binary files /dev/null and b/app/src/main/res/drawable/i23b.png differ diff --git a/app/src/main/res/drawable/i24.png b/app/src/main/res/drawable/i24.png new file mode 100644 index 0000000..740ec3e Binary files /dev/null and b/app/src/main/res/drawable/i24.png differ diff --git a/app/src/main/res/drawable/i24a.png b/app/src/main/res/drawable/i24a.png new file mode 100644 index 0000000..740ec3e Binary files /dev/null and b/app/src/main/res/drawable/i24a.png differ diff --git a/app/src/main/res/drawable/i24b.png b/app/src/main/res/drawable/i24b.png new file mode 100644 index 0000000..266b14d Binary files /dev/null and b/app/src/main/res/drawable/i24b.png differ diff --git a/app/src/main/res/drawable/i25.png b/app/src/main/res/drawable/i25.png new file mode 100644 index 0000000..740ec3e Binary files /dev/null and b/app/src/main/res/drawable/i25.png differ diff --git a/app/src/main/res/drawable/i25a.png b/app/src/main/res/drawable/i25a.png new file mode 100644 index 0000000..740ec3e Binary files /dev/null and b/app/src/main/res/drawable/i25a.png differ diff --git a/app/src/main/res/drawable/i25b.png b/app/src/main/res/drawable/i25b.png new file mode 100644 index 0000000..266b14d Binary files /dev/null and b/app/src/main/res/drawable/i25b.png differ diff --git a/app/src/main/res/drawable/i26.png b/app/src/main/res/drawable/i26.png new file mode 100644 index 0000000..c25daac Binary files /dev/null and b/app/src/main/res/drawable/i26.png differ diff --git a/app/src/main/res/drawable/i27.png b/app/src/main/res/drawable/i27.png new file mode 100644 index 0000000..7b9edde Binary files /dev/null and b/app/src/main/res/drawable/i27.png differ diff --git a/app/src/main/res/drawable/i28.png b/app/src/main/res/drawable/i28.png new file mode 100644 index 0000000..a992009 Binary files /dev/null and b/app/src/main/res/drawable/i28.png differ diff --git a/app/src/main/res/drawable/i29.png b/app/src/main/res/drawable/i29.png new file mode 100644 index 0000000..74471a0 Binary files /dev/null and b/app/src/main/res/drawable/i29.png differ diff --git a/app/src/main/res/drawable/i30.png b/app/src/main/res/drawable/i30.png new file mode 100644 index 0000000..6599e5a Binary files /dev/null and b/app/src/main/res/drawable/i30.png differ diff --git a/app/src/main/res/drawable/i31.png b/app/src/main/res/drawable/i31.png new file mode 100644 index 0000000..2cf9ba4 Binary files /dev/null and b/app/src/main/res/drawable/i31.png differ diff --git a/app/src/main/res/drawable/i32.png b/app/src/main/res/drawable/i32.png new file mode 100644 index 0000000..7aaaa6c Binary files /dev/null and b/app/src/main/res/drawable/i32.png differ diff --git a/app/src/main/res/drawable/i33.png b/app/src/main/res/drawable/i33.png new file mode 100644 index 0000000..08f73e1 Binary files /dev/null and b/app/src/main/res/drawable/i33.png differ diff --git a/app/src/main/res/drawable/i34.png b/app/src/main/res/drawable/i34.png new file mode 100644 index 0000000..921058c Binary files /dev/null and b/app/src/main/res/drawable/i34.png differ diff --git a/app/src/main/res/drawable/i35.png b/app/src/main/res/drawable/i35.png new file mode 100644 index 0000000..9b3489f Binary files /dev/null and b/app/src/main/res/drawable/i35.png differ diff --git a/app/src/main/res/drawable/wmo.png b/app/src/main/res/drawable/wmo.png new file mode 100644 index 0000000..6136cfe Binary files /dev/null and b/app/src/main/res/drawable/wmo.png differ