From baaf4a1bafb652b5d49e739e5378087144a6e410 Mon Sep 17 00:00:00 2001 From: Luis Vidal Date: Wed, 6 Apr 2016 18:54:27 -0700 Subject: [PATCH] Refactor WeatherInfo class - Builder constructor takes now 3 args: city name, temp and temp unit. This is the minimun data that a weather service should provide when a weather update request is processed. - Float members have been changed to double. Setter/getter methods updated. - New setter/getter methods have been added to set current day high and low temp. Forecast list should be used only to provide weather forecast for upcoming days (this has been clearly documented). WeatherContract was updated to include these 2 new columns - Added javadoc to all public methods - Timestamp is not longer required in constructor. A new method setTimestamp has been added Change-Id: Ia1edcfef0e2268f3881fed076c6ad74a81ca7334 TICKET: CYNGNOS-2365 TICKET: CYNGNOS-2382 TICKET: CYNGNOS-2356 TICKET: CYNGNOS-2360 --- api/cm_current.txt | 36 +-- .../internal/CMWeatherManagerService.java | 11 +- .../providers/WeatherContract.java | 31 +- .../java/cyanogenmod/weather/WeatherInfo.java | 287 ++++++++++++------ .../weather/util/WeatherUtils.java | 12 +- system-api/cm_system-current.txt | 36 +-- 6 files changed, 266 insertions(+), 147 deletions(-) diff --git a/api/cm_current.txt b/api/cm_current.txt index 4c39eec..4242d32 100644 --- a/api/cm_current.txt +++ b/api/cm_current.txt @@ -1107,7 +1107,6 @@ package cyanogenmod.providers { field public static final android.net.Uri CONTENT_URI; field public static final android.net.Uri CURRENT_AND_FORECAST_WEATHER_URI; field public static final java.lang.String CURRENT_CITY = "city"; - field public static final java.lang.String CURRENT_CITY_ID = "city_id"; field public static final java.lang.String CURRENT_CONDITION = "condition"; field public static final java.lang.String CURRENT_CONDITION_CODE = "condition_code"; field public static final java.lang.String CURRENT_HUMIDITY = "humidity"; @@ -1123,6 +1122,8 @@ package cyanogenmod.providers { field public static final java.lang.String FORECAST_HIGH = "forecast_high"; field public static final java.lang.String FORECAST_LOW = "forecast_low"; field public static final android.net.Uri FORECAST_WEATHER_URI; + field public static final java.lang.String TODAYS_HIGH_TEMPERATURE = "todays_high"; + field public static final java.lang.String TODAYS_LOW_TEMPERATURE = "todays_low"; } public static final class WeatherContract.WeatherColumns.TempUnit { @@ -1342,46 +1343,47 @@ package cyanogenmod.weather { public final class WeatherInfo implements android.os.Parcelable { method public int describeContents(); method public java.lang.String getCity(); - method public java.lang.String getCityId(); method public int getConditionCode(); method public java.util.ArrayList getForecasts(); - method public float getHumidity(); - method public float getTemperature(); + method public double getHumidity(); + method public double getTemperature(); method public int getTemperatureUnit(); method public long getTimestamp(); - method public float getWindDirection(); - method public float getWindSpeed(); + method public double getTodaysHigh(); + method public double getTodaysLow(); + method public double getWindDirection(); + method public double getWindSpeed(); method public int getWindSpeedUnit(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public static class WeatherInfo.Builder { - ctor public WeatherInfo.Builder(long); + ctor public WeatherInfo.Builder(java.lang.String, double, int); method public cyanogenmod.weather.WeatherInfo build(); - method public cyanogenmod.weather.WeatherInfo.Builder setCity(java.lang.String, java.lang.String); method public cyanogenmod.weather.WeatherInfo.Builder setForecast(java.util.ArrayList); - method public cyanogenmod.weather.WeatherInfo.Builder setHumidity(float); - method public cyanogenmod.weather.WeatherInfo.Builder setTemperature(float, int); + method public cyanogenmod.weather.WeatherInfo.Builder setHumidity(double); + method public cyanogenmod.weather.WeatherInfo.Builder setTimestamp(long); + method public cyanogenmod.weather.WeatherInfo.Builder setTodaysHigh(double); + method public cyanogenmod.weather.WeatherInfo.Builder setTodaysLow(double); method public cyanogenmod.weather.WeatherInfo.Builder setWeatherCondition(int); - method public cyanogenmod.weather.WeatherInfo.Builder setWind(float, float, int); + method public cyanogenmod.weather.WeatherInfo.Builder setWind(double, double, int); } public static class WeatherInfo.DayForecast implements android.os.Parcelable { method public int describeContents(); method public int getConditionCode(); - method public float getHigh(); - method public float getLow(); + method public double getHigh(); + method public double getLow(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public static class WeatherInfo.DayForecast.Builder { - ctor public WeatherInfo.DayForecast.Builder(); + ctor public WeatherInfo.DayForecast.Builder(int); method public cyanogenmod.weather.WeatherInfo.DayForecast build(); - method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setHigh(float); - method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setLow(float); - method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setWeatherCondition(int); + method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setHigh(double); + method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setLow(double); } public final class WeatherLocation implements android.os.Parcelable { diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMWeatherManagerService.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMWeatherManagerService.java index d34454e..aa8358e 100644 --- a/cm/lib/main/java/org/cyanogenmod/platform/internal/CMWeatherManagerService.java +++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/CMWeatherManagerService.java @@ -398,16 +398,17 @@ public class CMWeatherManagerService extends SystemService{ List contentValuesList = new ArrayList<>(size); ContentValues contentValues = new ContentValues(); - contentValues.put(WeatherColumns.CURRENT_CITY_ID, wi.getCityId()); contentValues.put(WeatherColumns.CURRENT_CITY, wi.getCity()); - contentValues.put(WeatherColumns.CURRENT_CONDITION_CODE, wi.getConditionCode()); - contentValues.put(WeatherColumns.CURRENT_HUMIDITY, wi.getHumidity()); contentValues.put(WeatherColumns.CURRENT_TEMPERATURE, wi.getTemperature()); contentValues.put(WeatherColumns.CURRENT_TEMPERATURE_UNIT, wi.getTemperatureUnit()); - contentValues.put(WeatherColumns.CURRENT_TIMESTAMP, wi.getTimestamp()); - contentValues.put(WeatherColumns.CURRENT_WIND_DIRECTION, wi.getWindDirection()); + contentValues.put(WeatherColumns.CURRENT_CONDITION_CODE, wi.getConditionCode()); + contentValues.put(WeatherColumns.CURRENT_HUMIDITY, wi.getHumidity()); contentValues.put(WeatherColumns.CURRENT_WIND_SPEED, wi.getWindSpeed()); + contentValues.put(WeatherColumns.CURRENT_WIND_DIRECTION, wi.getWindDirection()); contentValues.put(WeatherColumns.CURRENT_WIND_SPEED_UNIT, wi.getWindSpeedUnit()); + contentValues.put(WeatherColumns.CURRENT_TIMESTAMP, wi.getTimestamp()); + contentValues.put(WeatherColumns.TODAYS_HIGH_TEMPERATURE, wi.getTodaysHigh()); + contentValues.put(WeatherColumns.TODAYS_LOW_TEMPERATURE, wi.getTodaysLow()); contentValuesList.add(contentValues); for (WeatherInfo.DayForecast df : wi.getForecasts()) { diff --git a/sdk/src/java/cyanogenmod/providers/WeatherContract.java b/sdk/src/java/cyanogenmod/providers/WeatherContract.java index e8e3726..1103fc8 100644 --- a/sdk/src/java/cyanogenmod/providers/WeatherContract.java +++ b/sdk/src/java/cyanogenmod/providers/WeatherContract.java @@ -43,13 +43,6 @@ public class WeatherContract { public static final Uri FORECAST_WEATHER_URI = Uri.withAppendedPath(CONTENT_URI, "forecast"); - /** - * A unique ID for the city. NOTE: this value fully depends on the implementation of the - * weather provider service and can potentially change when you switch providers. - *

Type: TEXT

- */ - public static final String CURRENT_CITY_ID = "city_id"; - /** * The city name *

Type: TEXT

@@ -72,7 +65,7 @@ public class WeatherContract { /** * The current weather temperature - *

Type: FLOAT

+ *

Type: DOUBLE

*/ public static final String CURRENT_TEMPERATURE = "temperature"; @@ -89,19 +82,19 @@ public class WeatherContract { /** * The current weather humidity - *

Type: FLOAT

+ *

Type: DOUBLE

*/ public static final String CURRENT_HUMIDITY = "humidity"; /** * The current wind direction (in degrees) - *

Type: FLOAT

+ *

Type: DOUBLE

*/ public static final String CURRENT_WIND_DIRECTION = "wind_direction"; /** * The current wind speed - *

Type: FLOAT

+ *

Type: DOUBLE

*/ public static final String CURRENT_WIND_SPEED = "wind_speed"; @@ -122,15 +115,27 @@ public class WeatherContract { */ public static final String CURRENT_TIMESTAMP = "timestamp"; + /** + * Today's high temperature. + *

Type: DOUBLE

+ */ + public static final String TODAYS_HIGH_TEMPERATURE = "todays_high"; + + /** + * Today's low temperature. + *

Type: DOUBLE

+ */ + public static final String TODAYS_LOW_TEMPERATURE = "todays_low"; + /** * The forecasted low temperature - *

Type: FLOAT

+ *

Type: DOUBLE

*/ public static final String FORECAST_LOW = "forecast_low"; /** * The forecasted high temperature - *

Type: FLOAT

+ *

Type: DOUBLE

*/ public static final String FORECAST_HIGH = "forecast_high"; diff --git a/sdk/src/java/cyanogenmod/weather/WeatherInfo.java b/sdk/src/java/cyanogenmod/weather/WeatherInfo.java index 7d8686e..95fb2b7 100755 --- a/sdk/src/java/cyanogenmod/weather/WeatherInfo.java +++ b/sdk/src/java/cyanogenmod/weather/WeatherInfo.java @@ -19,7 +19,6 @@ package cyanogenmod.weather; import android.annotation.NonNull; import android.os.Parcel; import android.os.Parcelable; - import cyanogenmod.os.Build; import cyanogenmod.os.Concierge; import cyanogenmod.os.Concierge.ParcelInfo; @@ -41,63 +40,81 @@ import java.util.ArrayList; */ public final class WeatherInfo implements Parcelable { - private String mCityId; private String mCity; private int mConditionCode; - private float mTemperature; + private double mTemperature; private int mTempUnit; - private float mHumidity; - private float mWindSpeed; - private float mWindDirection; + private double mTodaysHighTemp; + private double mTodaysLowTemp; + private double mHumidity; + private double mWindSpeed; + private double mWindDirection; private int mWindSpeedUnit; private long mTimestamp; private ArrayList mForecastList; - int mKey; + private int mKey; private WeatherInfo() {} + /** + * Builder class for {@link WeatherInfo} + */ public static class Builder { - private String mCityId; private String mCity; - private int mConditionCode; - private float mTemperature; + private int mConditionCode = WeatherContract.WeatherColumns.WeatherCode.NOT_AVAILABLE; + private double mTemperature; private int mTempUnit; - private float mHumidity; - private float mWindSpeed; - private float mWindDirection; - private int mWindSpeedUnit; - private long mTimestamp; - private ArrayList mForecastList; + private double mTodaysHighTemp = Double.NaN; + private double mTodaysLowTemp = Double.NaN; + private double mHumidity = Double.NaN; + private double mWindSpeed = Double.NaN; + private double mWindDirection = Double.NaN; + private int mWindSpeedUnit = WeatherContract.WeatherColumns.WindSpeedUnit.MPH; + private long mTimestamp = -1; + private ArrayList mForecastList = new ArrayList<>(0); - public Builder(long timestamp) { - mTimestamp = timestamp; - } - - public Builder setCity(String cityId, @NonNull String cityName) { - if (cityName == null || cityId == null) { - throw new IllegalArgumentException("City name and id can't be null"); + /** + * @param cityName A valid city name. Attempting to pass null will get you an + * IllegalArgumentException + * @param temperature A valid temperature value. Attempting pass an invalid double value, + * will get you an IllegalArgumentException + * @param tempUnit A valid temperature unit value. See + * {@link cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit} for + * valid values. Attempting to pass an invalid temperature unit will get you + * an IllegalArgumentException + */ + public Builder(@NonNull String cityName, double temperature, int tempUnit) { + if (cityName == null) { + throw new IllegalArgumentException("City name can't be null"); + } + if (Double.isNaN(temperature)) { + throw new IllegalArgumentException("Invalid temperature"); } - mCityId = cityId; - mCity = cityName; - return this; - } - - public Builder setTemperature(float temperature, int tempUnit) { if (!isValidTempUnit(tempUnit)) { throw new IllegalArgumentException("Invalid temperature unit"); } + this.mCity = cityName; + this.mTemperature = temperature; + this.mTempUnit = tempUnit; + } - if (Float.isNaN(temperature)) { - throw new IllegalArgumentException("Invalid temperature value"); - } - - mTemperature = temperature; - mTempUnit = tempUnit; + /** + * @param timeStamp A timestamp indicating when this data was generated. If timestamps is + * not set, then the builder will set it to the time of object creation + * @return The {@link Builder} instance + */ + public Builder setTimestamp(long timeStamp) { + mTimestamp = timeStamp; return this; } - public Builder setHumidity(float humidity) { - if (Float.isNaN(humidity)) { + /** + * @param humidity The weather humidity. Attempting to pass an invalid double value will get + * you an IllegalArgumentException + * @return The {@link Builder} instance + */ + public Builder setHumidity(double humidity) { + if (Double.isNaN(humidity)) { throw new IllegalArgumentException("Invalid humidity value"); } @@ -105,11 +122,22 @@ public final class WeatherInfo implements Parcelable { return this; } - public Builder setWind(float windSpeed, float windDirection, int windSpeedUnit) { - if (Float.isNaN(windSpeed)) { + /** + * @param windSpeed The wind speed. Attempting to pass an invalid double value will get you + * an IllegalArgumentException + * @param windDirection The wind direction. Attempting to pass an invalid double value will + * get you an IllegalArgumentException + * @param windSpeedUnit A valid wind speed direction unit. See + * {@link cyanogenmod.providers.WeatherContract.WeatherColumns.WindSpeedUnit} + * for valid values. Attempting to pass an invalid speed unit will get + * you an IllegalArgumentException + * @return The {@link Builder} instance + */ + public Builder setWind(double windSpeed, double windDirection, int windSpeedUnit) { + if (Double.isNaN(windSpeed)) { throw new IllegalArgumentException("Invalid wind speed value"); } - if (Float.isNaN(windDirection)) { + if (Double.isNaN(windDirection)) { throw new IllegalArgumentException("Invalid wind direction value"); } if (!isValidWindSpeedUnit(windSpeedUnit)) { @@ -121,6 +149,13 @@ public final class WeatherInfo implements Parcelable { return this; } + /** + * @param conditionCode A valid weather condition code. See + * {@link cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode} + * for valid codes. Attempting to pass an invalid code will get you an + * IllegalArgumentException. + * @return The {@link Builder} instance + */ public Builder setWeatherCondition(int conditionCode) { if (!isValidWeatherCode(conditionCode)) { throw new IllegalArgumentException("Invalid weather condition code"); @@ -129,6 +164,11 @@ public final class WeatherInfo implements Parcelable { return this; } + /** + * @param forecasts A valid array list of {@link DayForecast} objects. Attempting to pass + * null will get you an IllegalArgumentException' + * @return The {@link Builder} instance + */ public Builder setForecast(@NonNull ArrayList forecasts) { if (forecasts == null) { throw new IllegalArgumentException("Forecast list can't be null"); @@ -137,9 +177,39 @@ public final class WeatherInfo implements Parcelable { return this; } + /** + * + * @param todaysHigh Today's high temperature. Attempting to pass an invalid double value + * will get you an IllegalArgumentException + * @return The {@link Builder} instance + */ + public Builder setTodaysHigh(double todaysHigh) { + if (Double.isNaN(todaysHigh)) { + throw new IllegalArgumentException("Invalid temperature value"); + } + mTodaysHighTemp = todaysHigh; + return this; + } + + /** + * @param todaysLow Today's low temperature. Attempting to pass an invalid double value will + * get you an IllegalArgumentException + * @return + */ + public Builder setTodaysLow(double todaysLow) { + if (Double.isNaN(todaysLow)) { + throw new IllegalArgumentException("Invalid temperature value"); + } + mTodaysLowTemp = todaysLow; + return this; + } + + /** + * Combine all of the options that have been set and return a new {@link WeatherInfo} object + * @return {@link WeatherInfo} + */ public WeatherInfo build() { WeatherInfo info = new WeatherInfo(); - info.mCityId = this.mCityId; info.mCity = this.mCity; info.mConditionCode = this.mConditionCode; info.mTemperature = this.mTemperature; @@ -148,7 +218,7 @@ public final class WeatherInfo implements Parcelable { info.mWindSpeed = this.mWindSpeed; info.mWindDirection = this.mWindDirection; info.mWindSpeedUnit = this.mWindSpeedUnit; - info.mTimestamp = this.mTimestamp; + info.mTimestamp = this.mTimestamp == -1 ? System.currentTimeMillis() : this.mTimestamp; info.mForecastList = this.mForecastList; info.mKey = this.hashCode(); return info; @@ -186,13 +256,6 @@ public final class WeatherInfo implements Parcelable { return true; } - /** - * @return city id - */ - public String getCityId() { - return mCityId; - } - /** * @return city name */ @@ -210,7 +273,7 @@ public final class WeatherInfo implements Parcelable { /** * @return humidity */ - public float getHumidity() { + public double getHumidity() { return mHumidity; } @@ -224,14 +287,14 @@ public final class WeatherInfo implements Parcelable { /** * @return wind direction (degrees) */ - public float getWindDirection() { + public double getWindDirection() { return mWindDirection; } /** * @return wind speed */ - public float getWindSpeed() { + public double getWindSpeed() { return mWindSpeed; } @@ -245,7 +308,7 @@ public final class WeatherInfo implements Parcelable { /** * @return current temperature */ - public float getTemperature() { + public double getTemperature() { return mTemperature; } @@ -257,10 +320,26 @@ public final class WeatherInfo implements Parcelable { } /** - * @return List of {@link cyanogenmod.weather.WeatherInfo.DayForecast} + * @return today's high temperature + */ + public double getTodaysHigh() { + return mTodaysHighTemp; + } + + /** + * @return today's low temperature + */ + public double getTodaysLow() { + return mTodaysLowTemp; + } + + /** + * @return List of {@link cyanogenmod.weather.WeatherInfo.DayForecast}. This list will contain + * the forecast weather for the upcoming days. If you want to know today's high and low + * temperatures, use {@link WeatherInfo#getTodaysHigh()} and {@link WeatherInfo#getTodaysLow()} */ public ArrayList getForecasts() { - return mForecastList; + return new ArrayList<>(mForecastList); } private WeatherInfo(Parcel parcel) { @@ -270,15 +349,16 @@ public final class WeatherInfo implements Parcelable { if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) { mKey = parcel.readInt(); - mCityId = parcel.readString(); mCity = parcel.readString(); mConditionCode = parcel.readInt(); - mTemperature = parcel.readFloat(); + mTemperature = parcel.readDouble(); mTempUnit = parcel.readInt(); - mHumidity = parcel.readFloat(); - mWindSpeed = parcel.readFloat(); - mWindDirection = parcel.readFloat(); + mHumidity = parcel.readDouble(); + mWindSpeed = parcel.readDouble(); + mWindDirection = parcel.readDouble(); mWindSpeedUnit = parcel.readInt(); + mTodaysHighTemp = parcel.readDouble(); + mTodaysLowTemp = parcel.readDouble(); mTimestamp = parcel.readLong(); int forecastListSize = parcel.readInt(); mForecastList = new ArrayList<>(); @@ -304,15 +384,16 @@ public final class WeatherInfo implements Parcelable { // ==== ELDERBERRY ===== dest.writeInt(mKey); - dest.writeString(mCityId); dest.writeString(mCity); dest.writeInt(mConditionCode); - dest.writeFloat(mTemperature); + dest.writeDouble(mTemperature); dest.writeInt(mTempUnit); - dest.writeFloat(mHumidity); - dest.writeFloat(mWindSpeed); - dest.writeFloat(mWindDirection); + dest.writeDouble(mHumidity); + dest.writeDouble(mWindSpeed); + dest.writeDouble(mWindDirection); dest.writeInt(mWindSpeedUnit); + dest.writeDouble(mTodaysHighTemp); + dest.writeDouble(mTodaysLowTemp); dest.writeLong(mTimestamp); dest.writeInt(mForecastList.size()); for (DayForecast dayForecast : mForecastList) { @@ -338,45 +419,72 @@ public final class WeatherInfo implements Parcelable { }; /** - * This class represents the weather forecast for a given day + * This class represents the weather forecast for a given day. Do not add low and high + * temperatures for the current day in this list. Use + * {@link WeatherInfo.Builder#setTodaysHigh(double)} and + * {@link WeatherInfo.Builder#setTodaysLow(double)} instead. */ public static class DayForecast implements Parcelable{ - float mLow; - float mHigh; + double mLow; + double mHigh; int mConditionCode; int mKey; private DayForecast() {} + /** + * Builder class for {@link DayForecast} + */ public static class Builder { - float mLow; - float mHigh; + double mLow = Double.NaN; + double mHigh = Double.NaN; int mConditionCode; - public Builder() {} - public Builder setHigh(float high) { - if (Float.isNaN(high)) { + /** + * @param conditionCode A valid weather condition code. See + * {@link cyanogenmod.providers.WeatherContract.WeatherColumns.WeatherCode} for valid + * values. Attempting to pass an invalid code will get you an + * IllegalArgumentException + */ + public Builder(int conditionCode) { + if (!isValidWeatherCode(conditionCode)) { + throw new IllegalArgumentException("Invalid weather condition code"); + } + mConditionCode = conditionCode; + } + + /** + * @param high Forecast high temperature for this day. Attempting to pass an invalid + * double value will get you an IllegalArgumentException + * @return The {@link Builder} instance + */ + public Builder setHigh(double high) { + if (Double.isNaN(high)) { throw new IllegalArgumentException("Invalid high forecast temperature"); } mHigh = high; return this; } - public Builder setLow(float low) { - if (Float.isNaN(low)) { + + /** + * @param low Forecast low temperate for this day. Attempting to pass an invalid double + * value will get you an IllegalArgumentException + * @return The {@link Builder} instance + */ + public Builder setLow(double low) { + if (Double.isNaN(low)) { throw new IllegalArgumentException("Invalid low forecast temperature"); } mLow = low; return this; } - public Builder setWeatherCondition(int code) { - if (!isValidWeatherCode(code)) { - throw new IllegalArgumentException("Invalid weather condition code"); - } - mConditionCode = code; - return this; - } + /** + * Combine all of the options that have been set and return a new {@link DayForecast} + * object + * @return {@link DayForecast} + */ public DayForecast build() { DayForecast forecast = new DayForecast(); forecast.mLow = this.mLow; @@ -390,14 +498,14 @@ public final class WeatherInfo implements Parcelable { /** * @return forecasted low temperature */ - public float getLow() { + public double getLow() { return mLow; } /** * @return not what you think. Returns the forecasted high temperature */ - public float getHigh() { + public double getHigh() { return mHigh; } @@ -420,8 +528,8 @@ public final class WeatherInfo implements Parcelable { // ==== ELDERBERRY ===== dest.writeInt(mKey); - dest.writeFloat(mLow); - dest.writeFloat(mHigh); + dest.writeDouble(mLow); + dest.writeDouble(mHigh); dest.writeInt(mConditionCode); // Complete parcel info for the concierge @@ -448,8 +556,8 @@ public final class WeatherInfo implements Parcelable { if (parcelableVersion >= Build.CM_VERSION_CODES.ELDERBERRY) { mKey = parcel.readInt(); - mLow = parcel.readFloat(); - mHigh = parcel.readFloat(); + mLow = parcel.readDouble(); + mHigh = parcel.readDouble(); mConditionCode = parcel.readInt(); } @@ -488,7 +596,6 @@ public final class WeatherInfo implements Parcelable { @Override public String toString() { StringBuilder builder = new StringBuilder() - .append("{CityId: ").append(mCityId) .append(" City Name: ").append(mCity) .append(" Condition Code: ").append(mConditionCode) .append(" Temperature: ").append(mTemperature) @@ -497,6 +604,8 @@ public final class WeatherInfo implements Parcelable { .append(" Wind speed: ").append(mWindSpeed) .append(" Wind direction: ").append(mWindDirection) .append(" Wind Speed Unit: ").append(mWindSpeedUnit) + .append(" Today's high temp: ").append(mTodaysHighTemp) + .append(" Today's low temp: ").append(mTodaysLowTemp) .append(" Timestamp: ").append(mTimestamp).append(" Forecasts: ["); for (DayForecast dayForecast : mForecastList) { builder.append(dayForecast.toString()); diff --git a/sdk/src/java/cyanogenmod/weather/util/WeatherUtils.java b/sdk/src/java/cyanogenmod/weather/util/WeatherUtils.java index c89213b..0e6ceed 100644 --- a/sdk/src/java/cyanogenmod/weather/util/WeatherUtils.java +++ b/sdk/src/java/cyanogenmod/weather/util/WeatherUtils.java @@ -31,8 +31,8 @@ public class WeatherUtils { * @param celsius temperature in Celsius * @return the temperature in degrees Fahrenheit */ - public static float celsiusToFahrenheit(float celsius) { - return ((celsius * (9f/5f)) + 32f); + public static double celsiusToFahrenheit(double celsius) { + return ((celsius * (9d/5d)) + 32d); } /** @@ -40,8 +40,8 @@ public class WeatherUtils { * @param fahrenheit temperature in Fahrenheit * @return the temperature in degrees Celsius */ - public static float fahrenheitToCelsius(float fahrenheit) { - return ((fahrenheit - 32f) * (5f/9f)); + public static double fahrenheitToCelsius(double fahrenheit) { + return ((fahrenheit - 32d) * (5d/9d)); } /** @@ -52,9 +52,9 @@ public class WeatherUtils { * @return A string with the format XX°F or XX°C (where XX is the temperature) * depending on the temperature unit that was provided or null if an invalid unit is supplied */ - public static String formatTemperature(float temperature, int tempUnit) { + public static String formatTemperature(double temperature, int tempUnit) { if (!isValidTempUnit(tempUnit)) return null; - if (Float.isNaN(temperature)) return "-"; + if (Double.isNaN(temperature)) return "-"; DecimalFormat noDigitsFormat = new DecimalFormat("0"); String noDigitsTemp = noDigitsFormat.format(temperature); diff --git a/system-api/cm_system-current.txt b/system-api/cm_system-current.txt index 4c39eec..4242d32 100644 --- a/system-api/cm_system-current.txt +++ b/system-api/cm_system-current.txt @@ -1107,7 +1107,6 @@ package cyanogenmod.providers { field public static final android.net.Uri CONTENT_URI; field public static final android.net.Uri CURRENT_AND_FORECAST_WEATHER_URI; field public static final java.lang.String CURRENT_CITY = "city"; - field public static final java.lang.String CURRENT_CITY_ID = "city_id"; field public static final java.lang.String CURRENT_CONDITION = "condition"; field public static final java.lang.String CURRENT_CONDITION_CODE = "condition_code"; field public static final java.lang.String CURRENT_HUMIDITY = "humidity"; @@ -1123,6 +1122,8 @@ package cyanogenmod.providers { field public static final java.lang.String FORECAST_HIGH = "forecast_high"; field public static final java.lang.String FORECAST_LOW = "forecast_low"; field public static final android.net.Uri FORECAST_WEATHER_URI; + field public static final java.lang.String TODAYS_HIGH_TEMPERATURE = "todays_high"; + field public static final java.lang.String TODAYS_LOW_TEMPERATURE = "todays_low"; } public static final class WeatherContract.WeatherColumns.TempUnit { @@ -1342,46 +1343,47 @@ package cyanogenmod.weather { public final class WeatherInfo implements android.os.Parcelable { method public int describeContents(); method public java.lang.String getCity(); - method public java.lang.String getCityId(); method public int getConditionCode(); method public java.util.ArrayList getForecasts(); - method public float getHumidity(); - method public float getTemperature(); + method public double getHumidity(); + method public double getTemperature(); method public int getTemperatureUnit(); method public long getTimestamp(); - method public float getWindDirection(); - method public float getWindSpeed(); + method public double getTodaysHigh(); + method public double getTodaysLow(); + method public double getWindDirection(); + method public double getWindSpeed(); method public int getWindSpeedUnit(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public static class WeatherInfo.Builder { - ctor public WeatherInfo.Builder(long); + ctor public WeatherInfo.Builder(java.lang.String, double, int); method public cyanogenmod.weather.WeatherInfo build(); - method public cyanogenmod.weather.WeatherInfo.Builder setCity(java.lang.String, java.lang.String); method public cyanogenmod.weather.WeatherInfo.Builder setForecast(java.util.ArrayList); - method public cyanogenmod.weather.WeatherInfo.Builder setHumidity(float); - method public cyanogenmod.weather.WeatherInfo.Builder setTemperature(float, int); + method public cyanogenmod.weather.WeatherInfo.Builder setHumidity(double); + method public cyanogenmod.weather.WeatherInfo.Builder setTimestamp(long); + method public cyanogenmod.weather.WeatherInfo.Builder setTodaysHigh(double); + method public cyanogenmod.weather.WeatherInfo.Builder setTodaysLow(double); method public cyanogenmod.weather.WeatherInfo.Builder setWeatherCondition(int); - method public cyanogenmod.weather.WeatherInfo.Builder setWind(float, float, int); + method public cyanogenmod.weather.WeatherInfo.Builder setWind(double, double, int); } public static class WeatherInfo.DayForecast implements android.os.Parcelable { method public int describeContents(); method public int getConditionCode(); - method public float getHigh(); - method public float getLow(); + method public double getHigh(); + method public double getLow(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; } public static class WeatherInfo.DayForecast.Builder { - ctor public WeatherInfo.DayForecast.Builder(); + ctor public WeatherInfo.DayForecast.Builder(int); method public cyanogenmod.weather.WeatherInfo.DayForecast build(); - method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setHigh(float); - method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setLow(float); - method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setWeatherCondition(int); + method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setHigh(double); + method public cyanogenmod.weather.WeatherInfo.DayForecast.Builder setLow(double); } public final class WeatherLocation implements android.os.Parcelable {