Skip to content

Commit

Permalink
Merge "Lockscreen: Keep weather info up to date" into jellybean
Browse files Browse the repository at this point in the history
  • Loading branch information
Jef Oliver authored and Gerrit Code Review committed Sep 2, 2012
2 parents 9366afd + 30054ce commit 9c38da8
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -290,6 +290,7 @@ public KeyguardStatusViewManager(View view, KeyguardUpdateMonitor updateMonitor,
private static WeatherInfo mWeatherInfo = new WeatherInfo();
private static final int QUERY_WEATHER = 0;
private static final int UPDATE_WEATHER = 1;
private boolean mWeatherRefreshing;

private Handler mHandler = new Handler() {
@Override
Expand Down Expand Up @@ -345,6 +346,7 @@ public void run() {
mHandler.sendMessage(msg);
}
});
mWeatherRefreshing = true;
queryWeather.setPriority(Thread.MIN_PRIORITY);
queryWeather.start();
break;
Expand All @@ -359,13 +361,15 @@ public void run() {
w = parseXml(getDocument(woeid));
} catch (Exception e) {
}
mWeatherRefreshing = false;
if (w == null) {
setNoWeatherData();
} else {
setWeatherData(w);
mWeatherInfo = w;
}
} else {
mWeatherRefreshing = false;
if (mWeatherInfo.temp.equals(WeatherInfo.NODATA)) {
setNoWeatherData();
} else {
Expand All @@ -389,7 +393,9 @@ private void refreshWeather() {
Settings.System.WEATHER_UPDATE_INTERVAL, 60); // Default to hourly
boolean manualSync = (interval == 0);
if (!manualSync && (((System.currentTimeMillis() - mWeatherInfo.last_sync) / 60000) >= interval)) {
mHandler.sendEmptyMessage(QUERY_WEATHER);
if (!mWeatherRefreshing) {
mHandler.sendEmptyMessage(QUERY_WEATHER);
}
} else if (manualSync && mWeatherInfo.last_sync == 0) {
setNoWeatherData();
} else {
Expand Down Expand Up @@ -437,7 +443,7 @@ private void setWeatherData(WeatherInfo w) {
mWeatherCity.setText(w.city);
mWeatherCity.setVisibility(showLocation ? View.VISIBLE : View.GONE);
}
if (mWeatherCondition != null) {
if (mWeatherCondition != null && !mWeatherRefreshing) {
mWeatherCondition.setText(w.condition);
mWeatherCondition.setVisibility(View.VISIBLE);
}
Expand Down Expand Up @@ -476,7 +482,7 @@ private void setNoWeatherData() {
mWeatherCity.setText(R.string.weather_no_data);
mWeatherCity.setVisibility(View.VISIBLE);
}
if (mWeatherCondition != null) {
if (mWeatherCondition != null && !mWeatherRefreshing) {
mWeatherCondition.setText(R.string.weather_tap_to_refresh);
}
if (mWeatherUpdateTime != null) {
Expand Down Expand Up @@ -666,6 +672,7 @@ public void onResume() {
if (mDigitalClock != null) {
mDigitalClock.updateTime();
}
refreshWeather();

mUpdateMonitor.registerInfoCallback(mInfoCallback);
mUpdateMonitor.registerSimStateCallback(mSimStateCallback);
Expand Down Expand Up @@ -1020,6 +1027,7 @@ public void onRefreshBatteryInfo(boolean showBatteryInfo, boolean pluggedIn,
@Override
public void onTimeChanged() {
refreshDate();
refreshWeather();
}

@Override
Expand Down Expand Up @@ -1054,7 +1062,7 @@ public void onClick(View v) {
}

mCallback.pokeWakelock();
if (!mHandler.hasMessages(QUERY_WEATHER)) {
if (!mWeatherRefreshing) {
mHandler.sendEmptyMessage(QUERY_WEATHER);
}
}
Expand Down

0 comments on commit 9c38da8

Please sign in to comment.