summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/values/cm_colors.xml5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java3
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java118
3 files changed, 95 insertions, 31 deletions
diff --git a/packages/SystemUI/res/values/cm_colors.xml b/packages/SystemUI/res/values/cm_colors.xml
index f43316b8c9c..6f975f28cca 100644
--- a/packages/SystemUI/res/values/cm_colors.xml
+++ b/packages/SystemUI/res/values/cm_colors.xml
@@ -17,4 +17,9 @@
<resources>
<!-- Status bar battery level text color -->
<color name="status_bar_battery_level_text_color">#ffffff</color>
+
+ <!-- Expanded Status Bar Weather Text Colors -->
+ <color name="status_bar_temperature_text_color">#FFFFFFFF</color>
+ <color name="status_bar_temperature_location_text_color">#FFFFFFFF</color>
+
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java
index 1fa49568fd5..0f71bccaa82 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherController.java
@@ -25,8 +25,9 @@ public interface WeatherController {
void onWeatherChanged(WeatherInfo temp);
}
public static class WeatherInfo {
- public String temp = null;
+ public double temp = Double.NaN;
public String city = null;
public String condition = null;
+ public int tempUnit;
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java
index 288bc7efd8a..1a798f07d14 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/WeatherControllerImpl.java
@@ -16,43 +16,49 @@
package com.android.systemui.statusbar.policy;
-import android.content.BroadcastReceiver;
import android.content.ComponentName;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Handler;
-import android.provider.Settings;
import android.util.Log;
+import cyanogenmod.providers.CMSettings;
+import cyanogenmod.providers.WeatherContract;
+import cyanogenmod.weather.CMWeatherManager;
+import cyanogenmod.weather.util.WeatherUtils;
import java.util.ArrayList;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_CITY;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_CONDITION;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_TEMPERATURE;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.CURRENT_TEMPERATURE_UNIT;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.CELSIUS;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT;
+
public class WeatherControllerImpl implements WeatherController {
private static final String TAG = WeatherController.class.getSimpleName();
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+ private WeatherContentObserver mWeatherContentObserver;
+ private Handler mHandler;
+ private int mWeatherUnit;
+ private Uri mWeatherTempetarureUri;
public static final ComponentName COMPONENT_WEATHER_FORECAST = new ComponentName(
"com.cyanogenmod.lockclock", "com.cyanogenmod.lockclock.weather.ForecastActivity");
- public static final String ACTION_UPDATE_FINISHED
- = "com.cyanogenmod.lockclock.action.WEATHER_UPDATE_FINISHED";
- public static final String EXTRA_UPDATE_CANCELLED = "update_cancelled";
public static final String ACTION_FORCE_WEATHER_UPDATE
= "com.cyanogenmod.lockclock.action.FORCE_WEATHER_UPDATE";
- public static final Uri CURRENT_WEATHER_URI
- = Uri.parse("content://com.cyanogenmod.lockclock.weather.provider/weather/current");
- public static final String[] WEATHER_PROJECTION = new String[]{
- "temperature",
- "city",
- "condition"
+ private static final String[] WEATHER_PROJECTION = new String[]{
+ CURRENT_TEMPERATURE,
+ CURRENT_TEMPERATURE_UNIT,
+ CURRENT_CITY,
+ CURRENT_CONDITION
};
private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
- private final Receiver mReceiver = new Receiver();
private final Context mContext;
private WeatherInfo mCachedInfo = new WeatherInfo();
@@ -60,10 +66,16 @@ public class WeatherControllerImpl implements WeatherController {
public WeatherControllerImpl(Context context) {
mContext = context;
mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ mHandler = new Handler();
+ mWeatherContentObserver = new WeatherContentObserver(mHandler);
+ mWeatherTempetarureUri
+ = CMSettings.Global.getUriFor(CMSettings.Global.WEATHER_TEMPERATURE_UNIT);
+ mContext.getContentResolver().registerContentObserver(
+ WeatherContract.WeatherColumns.CURRENT_WEATHER_URI,true, mWeatherContentObserver);
+ mContext.getContentResolver().registerContentObserver(mWeatherTempetarureUri, true,
+ mWeatherContentObserver);
+ queryWeatherTempUnit();
queryWeather();
- final IntentFilter filter = new IntentFilter();
- filter.addAction(ACTION_UPDATE_FINISHED);
- mContext.registerReceiver(mReceiver, filter);
}
public void addCallback(Callback callback) {
@@ -85,17 +97,29 @@ public class WeatherControllerImpl implements WeatherController {
}
private void queryWeather() {
- Cursor c = mContext.getContentResolver().query(CURRENT_WEATHER_URI, WEATHER_PROJECTION,
+ Cursor c = mContext.getContentResolver().query(
+ WeatherContract.WeatherColumns.CURRENT_WEATHER_URI, WEATHER_PROJECTION,
null, null, null);
if (c == null) {
if(DEBUG) Log.e(TAG, "cursor was null for temperature, forcing weather update");
+ //LockClock keeps track of the user settings (temp unit, search by geo location/city)
+ //so we delegate the responsibility of handling a weather update to LockClock
mContext.sendBroadcast(new Intent(ACTION_FORCE_WEATHER_UPDATE));
} else {
try {
c.moveToFirst();
- mCachedInfo.temp = c.getString(0);
- mCachedInfo.city = c.getString(1);
- mCachedInfo.condition = c.getString(2);
+ double temp = c.getDouble(0);
+ int reportedUnit = c.getInt(1);
+ if (reportedUnit == CELSIUS && mWeatherUnit == FAHRENHEIT) {
+ temp = WeatherUtils.celsiusToFahrenheit(temp);
+ } else if (reportedUnit == FAHRENHEIT && mWeatherUnit == CELSIUS) {
+ temp = WeatherUtils.fahrenheitToCelsius(temp);
+ }
+
+ mCachedInfo.temp = temp;
+ mCachedInfo.tempUnit = mWeatherUnit;
+ mCachedInfo.city = c.getString(2);
+ mCachedInfo.condition = c.getString(3);
} finally {
c.close();
}
@@ -108,19 +132,53 @@ public class WeatherControllerImpl implements WeatherController {
}
}
- private final class Receiver extends BroadcastReceiver {
+ private class WeatherContentObserver extends ContentObserver {
+
+ public WeatherContentObserver(Handler handler) {
+ super(handler);
+ }
+
@Override
- public void onReceive(Context context, Intent intent) {
- if (DEBUG) Log.d(TAG, "onReceive " + intent.getAction());
- if (intent.hasExtra(EXTRA_UPDATE_CANCELLED)) {
- if (intent.getBooleanExtra(EXTRA_UPDATE_CANCELLED, false)) {
- // no update
- return;
+ public void onChange(boolean selfChange, Uri uri) {
+ if (uri != null) {
+ if (uri.compareTo(WeatherContract.WeatherColumns.CURRENT_WEATHER_URI) == 0) {
+ queryWeather();
+ fireCallback();
+ } else if (uri.compareTo(mWeatherTempetarureUri) == 0) {
+ queryWeatherTempUnit();
+ fixCachedWeatherInfo();
+ fireCallback();
+ } else {
+ super.onChange(selfChange, uri);
}
}
- queryWeather();
- fireCallback();
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ onChange(selfChange, null);
}
}
+ private void queryWeatherTempUnit() {
+ try {
+ mWeatherUnit = CMSettings.Global.getInt(mContext.getContentResolver(),
+ CMSettings.Global.WEATHER_TEMPERATURE_UNIT);
+ } catch (CMSettings.CMSettingNotFoundException e) {
+ //CMSettingsProvider should have taken care of setting a default value for this setting
+ //so how is that we ended up here?? We need to set a valid temp unit anyway to keep
+ //this going
+ mWeatherUnit = WeatherContract.WeatherColumns.TempUnit.CELSIUS;
+ }
+ }
+
+ private void fixCachedWeatherInfo() {
+ if (mCachedInfo.tempUnit == CELSIUS && mWeatherUnit == FAHRENHEIT) {
+ mCachedInfo.temp = WeatherUtils.celsiusToFahrenheit(mCachedInfo.temp);
+ mCachedInfo.tempUnit = FAHRENHEIT;
+ } else if (mCachedInfo.tempUnit == FAHRENHEIT && mWeatherUnit == CELSIUS) {
+ mCachedInfo.temp = WeatherUtils.fahrenheitToCelsius(mCachedInfo.temp);
+ mCachedInfo.tempUnit = CELSIUS;
+ }
+ }
}