// This fires when the homescreen requests an appwidget update. // This is the final fallback when the clock lags. @Override public void onUpdate(Context context, AppWidgetManager aWM, int[] appWidgetIds) { final int N = appWidgetIds.length; for (int i = 0; i < N; i++) { // For a brand new widget (but not established widgets), initialize the prefs if (OMC.PREFS.getString("widgetTheme" + i, "").equals("")) OMC.initPrefs(appWidgetIds[i]); // Redraw the widget. OMCWidgetDrawEngine.updateAppWidget(context, aWM, appWidgetIds[i], OMC.WIDGET2x1CNAME); } }
public void endDocument() { if (OMC.DEBUG) Log.i(OMC.OMCSHORT + "YrNoWeather", "End Document."); // // Build out the forecast array. Time day = new Time(); day.setToNow(); // while (HIGHTEMPS.containsKey(day.format("%Y%m%d"))) { // try { // JSONObject jsonOneDayForecast = new JSONObject(); // jsonOneDayForecast.put("day_of_week", day.format("%a")); // jsonOneDayForecast.put("condition", CONDITIONS.get(day.format("%Y%m%d"))); // jsonOneDayForecast.put("condition_lcase", // CONDITIONS.get(day.format("%Y%m%d")).toLowerCase()); // double lowc = OMC.roundToSignificantFigures(LOWTEMPS.get(day.format("%Y%m%d")),3); // double highc = OMC.roundToSignificantFigures(HIGHTEMPS.get(day.format("%Y%m%d")),3); // double lowf = (int)(lowc/5f*9f+32.5f); // double highf = (int)(highc/5f*9f+32.5f); // jsonOneDayForecast.put("low_c", lowc); // jsonOneDayForecast.put("high_c", highc); // jsonOneDayForecast.put("low", lowf); // jsonOneDayForecast.put("high", highf); // jsonWeather.getJSONArray("zzforecast_conditions").put( // jsonOneDayForecast); // day.hour+=24; // day.normalize(false); // } catch (JSONException e) { // e.printStackTrace(); // } // } if (OMC.DEBUG) Log.i(OMC.OMCSHORT + "YrNoWeather", jsonWeather.toString()); // Check if the reply was valid. // if (jsonWeather.optString("condition",null)==null || // jsonWeather.optString("problem_cause",null)!=null) { // //Google returned error - retry by city name, then abandon refresh // if (jsonWeather.optBoolean("bylatlong")) { // if (OMC.DEBUG) Log.i(OMC.OMCSHORT + "YrNoWeather", "Error using Lat/Long, retrying using // city name."); // YrNoWeatherXMLHandler.updateWeather(0d, 0d, jsonWeather.optString("country2"), // jsonWeather.optString("city2"), false); // return; // } else { // if (OMC.DEBUG) Log.i(OMC.OMCSHORT + "YrNoWeather", "Error using city name. No refresh."); // return; // } // } try { if (jsonWeather.optString("city") == null || jsonWeather.optString("city").equals("")) { if (!jsonWeather.optString("city2").equals("")) jsonWeather.putOpt("city", jsonWeather.optString("city2")); else if (!jsonWeather.optString("country2").equals("")) jsonWeather.putOpt("city", jsonWeather.optString("country2")); } // Mark weather forecast source. jsonWeather.put("source", "owm"); } catch (JSONException e) { e.printStackTrace(); return; } OMC.PREFS.edit().putString("weather", jsonWeather.toString()).commit(); OMC.LASTWEATHERREFRESH = System.currentTimeMillis(); if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Update Succeeded. Phone Time:" + new java.sql.Time(OMC.LASTWEATHERREFRESH).toLocaleString()); Time t = new Time(); // If the weather station information (international, mostly) doesn't have a timestamp, set the // timestamp to be jan 1st, 1970 t.parse(jsonWeather.optString("current_local_time", "19700101T000000")); // If the weather station info looks too stale (more than 2 hours old), it's because the phone's // date/time is wrong. // Force the update to the default update period if (System.currentTimeMillis() - t.toMillis(false) > 7200000l) { OMC.NEXTWEATHERREFRESH = Math.max( OMC.LASTWEATHERREFRESH + Long.parseLong(OMC.PREFS.getString("sWeatherFreq", "60")) * 60000l, OMC.LASTWEATHERTRY + Long.parseLong(OMC.PREFS.getString("sWeatherFreq", "60")) / 4l * 60000l); if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Weather Station Time:" + new java.sql.Time(t.toMillis(false)).toLocaleString()); if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Weather Station Time Missing or Stale. Using default interval."); } else if (t.toMillis(false) > System.currentTimeMillis()) { // If the weather station time is in the future, something is definitely wrong! // Force the update to the default update period if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Weather Station Time:" + new java.sql.Time(t.toMillis(false)).toLocaleString()); if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Weather Station Time in the future -> phone time is wrong. Using default interval."); OMC.NEXTWEATHERREFRESH = Math.max( OMC.LASTWEATHERREFRESH + Long.parseLong(OMC.PREFS.getString("sWeatherFreq", "60")) * 60000l, OMC.LASTWEATHERTRY + Long.parseLong(OMC.PREFS.getString("sWeatherFreq", "60")) / 4l * 60000l); } else { // If we get a recent weather station timestamp, we try to "catch" the update by setting next // update to // 29 minutes + default update period // after the last station refresh. if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Weather Station Time:" + new java.sql.Time(t.toMillis(false)).toLocaleString()); OMC.NEXTWEATHERREFRESH = Math.max( t.toMillis(false) + (29l + Long.parseLong(OMC.PREFS.getString("sWeatherFreq", "60"))) * 60000l, OMC.LASTWEATHERTRY + Long.parseLong(OMC.PREFS.getString("sWeatherFreq", "60")) / 4l * 60000l); } if (OMC.DEBUG) Log.i( OMC.OMCSHORT + "YrNoWeather", "Next Refresh Time:" + new java.sql.Time(OMC.NEXTWEATHERREFRESH).toLocaleString()); OMC.PREFS.edit().putLong("weather_nextweatherrefresh", OMC.NEXTWEATHERREFRESH).commit(); }