A lot
This commit is contained in:
@@ -11,7 +11,6 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@@ -26,6 +25,7 @@ import org.xml.sax.SAXException;
|
||||
|
||||
import com.flaremicro.util.Util;
|
||||
import com.flaremicro.visualforecast.forecast.DayForecast;
|
||||
import com.flaremicro.visualforecast.forecast.DetailedForecast;
|
||||
import com.flaremicro.visualforecast.forecast.ForecastDetails;
|
||||
import com.flaremicro.visualforecast.forecast.HourlyForecast;
|
||||
import com.flaremicro.visualforecast.forecast.TownForecast;
|
||||
@@ -77,7 +77,7 @@ public class ForecastProcessor implements Runnable {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void processHourlyForecast(TownForecast forecast, Document doc) {
|
||||
public HourlyForecast[] processHourlyForecast(Document doc) {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
NodeList hourlyForecast = doc.getElementsByTagName("hourlyForecast");
|
||||
@@ -106,7 +106,7 @@ public class ForecastProcessor implements Runnable {
|
||||
}
|
||||
}
|
||||
}
|
||||
forecast.setHourlyForecast(hourlyForecastArray.toArray(new HourlyForecast[0]));
|
||||
return hourlyForecastArray.toArray(new HourlyForecast[0]);
|
||||
}
|
||||
|
||||
public void processForecasts() {
|
||||
@@ -115,7 +115,6 @@ public class ForecastProcessor implements Runnable {
|
||||
ArrayList<TownForecast> townForecasts = new ArrayList<TownForecast>();
|
||||
for (TownInfo townInfo : towns)
|
||||
{
|
||||
DayForecast[] dayForecasts = new DayForecast[8];
|
||||
InputStream is = null;
|
||||
Document doc = null;
|
||||
try
|
||||
@@ -145,105 +144,136 @@ public class ForecastProcessor implements Runnable {
|
||||
|
||||
if (doc != null)
|
||||
{
|
||||
NodeList nodeList = doc.getElementsByTagName("forecast");
|
||||
for (int i = 0; i < nodeList.getLength(); i++)
|
||||
TownForecast tf = new TownForecast(townInfo.townName + ", " + townInfo.province, process7DayForecast(doc));
|
||||
townForecasts.add(tf);
|
||||
tf.setHourlyForecast(this.processHourlyForecast(doc));
|
||||
tf.setDetailedForecast(process36HourForecast(doc));
|
||||
tf.setSupportedDisplays(townInfo.getSupportedDisplays());
|
||||
}
|
||||
}
|
||||
|
||||
forecastDetails.setTownForecast(townForecasts.toArray(new TownForecast[0]));
|
||||
setMostRecentForecast(forecastDetails);
|
||||
}
|
||||
|
||||
private DetailedForecast[] process36HourForecast(Document doc)
|
||||
{
|
||||
DetailedForecast[] detailedForecast = new DetailedForecast[3];
|
||||
NodeList nodeList = doc.getElementsByTagName("forecast");
|
||||
for (int i = 0; i < Math.min(detailedForecast.length, nodeList.getLength()); i++)
|
||||
{
|
||||
if (nodeList.item(1).getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if (nodeList.item(1).getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
if (nodeList.item(1).getNodeType() == Node.ELEMENT_NODE)
|
||||
Element node = (Element) nodeList.item(i);
|
||||
String title = XMLUtils.getStringFromTagAttribute(node, "period", "textForecastName");
|
||||
String textForecast = XMLUtils.getStringFromTag(node, "textSummary");
|
||||
detailedForecast[i] = new DetailedForecast(title, textForecast);
|
||||
}
|
||||
}
|
||||
}
|
||||
return detailedForecast;
|
||||
}
|
||||
|
||||
private DayForecast[] process7DayForecast(Document doc)
|
||||
{
|
||||
DayForecast[] dayForecasts = new DayForecast[8];
|
||||
NodeList nodeList = doc.getElementsByTagName("forecast");
|
||||
for (int i = 0; i < nodeList.getLength(); i++)
|
||||
{
|
||||
if (nodeList.item(1).getNodeType() == Node.ELEMENT_NODE)
|
||||
{
|
||||
Element node = (Element) nodeList.item(i);
|
||||
int dayIndex = getDayIndex(XMLUtils.getStringFromTagAttribute(node, "period", "textForecastName"));
|
||||
Element abbForecast = XMLUtils.getFistElement(node, "abbreviatedForecast");
|
||||
int iconIndex = XMLUtils.getIntFromTag(abbForecast, "iconCode", ValueCheck.NO_DATA_INT);
|
||||
float percip = XMLUtils.getFloatFromTag(abbForecast, "pop", ValueCheck.NO_DATA_FLOAT);
|
||||
String textForecast = XMLUtils.getStringFromTag(abbForecast, "textSummary");
|
||||
|
||||
WeatherLines lines = dmt.weatherName(textForecast);
|
||||
byte icon = dmt.icon(iconIndex);
|
||||
|
||||
byte lo = ValueCheck.NO_DATA_BYTE;
|
||||
byte hi = ValueCheck.NO_DATA_BYTE;
|
||||
|
||||
Element element = XMLUtils.getFistElement(node, "temperatures");
|
||||
NodeList temps = element.getElementsByTagName("temperature");
|
||||
for (int j = 0; j < temps.getLength(); j++)
|
||||
{
|
||||
Node n = temps.item(j);
|
||||
try
|
||||
{
|
||||
Element node = (Element) nodeList.item(i);
|
||||
int dayIndex = getDayIndex(XMLUtils.getStringFromTagAttribute(node, "period", "textForecastName"));
|
||||
Element abbForecast = XMLUtils.getFistElement(node, "abbreviatedForecast");
|
||||
int iconIndex = XMLUtils.getIntFromTag(abbForecast, "iconCode", ValueCheck.NO_DATA_INT);
|
||||
float percip = XMLUtils.getFloatFromTag(abbForecast, "pop", ValueCheck.NO_DATA_FLOAT);
|
||||
String textForecast = XMLUtils.getStringFromTag(abbForecast, "textSummary");
|
||||
|
||||
WeatherLines lines = dmt.weatherName(textForecast);
|
||||
byte icon = dmt.icon(iconIndex);
|
||||
|
||||
byte lo = ValueCheck.NO_DATA_BYTE;
|
||||
byte hi = ValueCheck.NO_DATA_BYTE;
|
||||
|
||||
Element element = XMLUtils.getFistElement(node, "temperatures");
|
||||
NodeList temps = element.getElementsByTagName("temperature");
|
||||
for (int j = 0; j < temps.getLength(); j++)
|
||||
byte val = Byte.parseByte(n.getTextContent().trim());
|
||||
if (XMLUtils.getStringFromAttribute(n, "class").trim().equalsIgnoreCase("high"))
|
||||
{
|
||||
Node n = temps.item(j);
|
||||
try
|
||||
{
|
||||
byte val = Byte.parseByte(n.getTextContent().trim());
|
||||
if (XMLUtils.getStringFromAttribute(n, "class").trim().equalsIgnoreCase("high"))
|
||||
{
|
||||
hi = val;
|
||||
}
|
||||
else if (XMLUtils.getStringFromAttribute(n, "class").trim().equalsIgnoreCase("low"))
|
||||
{
|
||||
lo = val;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
|
||||
}
|
||||
hi = val;
|
||||
}
|
||||
|
||||
if (dayIndex >= 0 && dayIndex <= 7)
|
||||
else if (XMLUtils.getStringFromAttribute(n, "class").trim().equalsIgnoreCase("low"))
|
||||
{
|
||||
if (dayForecasts[dayIndex] != null)
|
||||
lo = val;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (dayIndex >= 0 && dayIndex <= 7)
|
||||
{
|
||||
if (dayForecasts[dayIndex] != null)
|
||||
{
|
||||
if (lo != ValueCheck.NO_DATA_BYTE && dayForecasts[dayIndex].loTemp == ValueCheck.NO_DATA_BYTE)
|
||||
{
|
||||
dayForecasts[dayIndex].loTemp = lo;
|
||||
}
|
||||
if (hi != ValueCheck.NO_DATA_BYTE && dayForecasts[dayIndex].hiTemp == ValueCheck.NO_DATA_BYTE)
|
||||
{
|
||||
dayForecasts[dayIndex].hiTemp = hi;
|
||||
}
|
||||
if (!ValueCheck.valueNoData(percip))
|
||||
{
|
||||
if (ValueCheck.valueNoData(dayForecasts[dayIndex].percipPercent))
|
||||
{
|
||||
if (lo != ValueCheck.NO_DATA_BYTE && dayForecasts[dayIndex].loTemp == ValueCheck.NO_DATA_BYTE)
|
||||
{
|
||||
dayForecasts[dayIndex].loTemp = lo;
|
||||
}
|
||||
if (hi != ValueCheck.NO_DATA_BYTE && dayForecasts[dayIndex].hiTemp == ValueCheck.NO_DATA_BYTE)
|
||||
{
|
||||
dayForecasts[dayIndex].hiTemp = hi;
|
||||
}
|
||||
if (!ValueCheck.valueNoData(percip))
|
||||
{
|
||||
if (ValueCheck.valueNoData(dayForecasts[dayIndex].percipPercent))
|
||||
{
|
||||
dayForecasts[dayIndex].percipPercent = percip;
|
||||
}
|
||||
else
|
||||
{
|
||||
dayForecasts[dayIndex].percipPercent = (dayForecasts[dayIndex].percipPercent + percip) - (percip * dayForecasts[dayIndex].percipPercent) / 100F;
|
||||
}
|
||||
}
|
||||
dayForecasts[dayIndex].percipPercent = percip;
|
||||
}
|
||||
else
|
||||
{
|
||||
dayForecasts[dayIndex] = new DayForecast(hi, lo, icon, lines.line1, lines.line2, percip);
|
||||
dayForecasts[dayIndex].percipPercent = (dayForecasts[dayIndex].percipPercent + percip) - (percip * dayForecasts[dayIndex].percipPercent) / 100F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < dayForecasts.length; i++)
|
||||
{
|
||||
if (dayForecasts[i] == null)
|
||||
else
|
||||
{
|
||||
dayForecasts[i] = new DayForecast();
|
||||
dayForecasts[dayIndex] = new DayForecast(hi, lo, icon, lines.line1, lines.line2, percip);
|
||||
}
|
||||
}
|
||||
TownForecast tf = new TownForecast(townInfo.townName + ", " + townInfo.province, dayForecasts);
|
||||
townForecasts.add(tf);
|
||||
this.processHourlyForecast(tf, doc);
|
||||
}
|
||||
}
|
||||
forecastDetails.setTownForecast(townForecasts.toArray(new TownForecast[0]));
|
||||
setMostRecentForecast(forecastDetails);
|
||||
for (int i = 0; i < dayForecasts.length; i++)
|
||||
{
|
||||
if (dayForecasts[i] == null)
|
||||
{
|
||||
dayForecasts[i] = new DayForecast();
|
||||
}
|
||||
}
|
||||
return dayForecasts;
|
||||
}
|
||||
|
||||
public void begin() {
|
||||
if (!running)
|
||||
{
|
||||
running = true;
|
||||
new Thread(this).start();
|
||||
self = new Thread(this);
|
||||
self.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void end() {
|
||||
running = false;
|
||||
self.interrupt();
|
||||
if(self != null)
|
||||
self.interrupt();
|
||||
}
|
||||
|
||||
public ForecastDetails getMostRecentForecast() {
|
||||
@@ -262,7 +292,6 @@ public class ForecastProcessor implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
self = Thread.currentThread();
|
||||
while (running)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user