Back to project page Weather.
The source code is released under:
Apache License
If you think the Android project Weather listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.volitic.weather; //from w ww. j av a 2 s . c o m import android.os.Parcel; import android.os.Parcelable; import java.util.HashMap; import java.util.Map; public class Weather implements Parcelable { public enum unit_system { METRIC, IMPERIAL, SI } private unit_system units_mode; // approx time of weather data fetch private long timestamp; public enum number { LATITUDE, LONGITUDE, SUNRISE, SUNSET, TEMPERATURE, TEMPERATURE_HIGH, TEMPERATURE_LOW, HUMIDITY, PRESSURE, WIND_SPEED, WIND_DIRECTION, CLOUD_COVER, PRECIPITATION, WEATHER_CODE } private Map<number, Float> numeric_data = new HashMap<number, Float>(); public enum text { LOCATION, POSTAL_CODE, WIND_TYPE, WIND_BEARING, PRECIPITATION_TYPE, QUALITATIVE_SUMMARY } private Map<text, String> text_data = new HashMap<text, String>(); public long time(){ return timestamp; } public float get( number type){ return numeric_data.get(type); } public String get(text type){ return text_data.get(type); } public unit_system getUnits(){ return units_mode; } public void set(number type, float value){ numeric_data.put(type, value); } public void set(text type, String value){ text_data.put(type, value); } public void setUnits(unit_system system){ units_mode = system; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { switch (units_mode){ case METRIC: dest.writeInt(0); break; case IMPERIAL: dest.writeInt(1); break; default: dest.writeInt(2); } dest.writeLong(timestamp); //add float values for(number nd : number.values()){ if(numeric_data.containsKey(nd)){ dest.writeFloat(numeric_data.get(nd)); } else { dest.writeFloat(Float.MIN_VALUE); } } //add string values for(text td : text.values()){ if(text_data.containsKey(td)){ dest.writeString(text_data.get(td)); } else { dest.writeString("NO DATA"); } } } public static final Parcelable.Creator<Weather> CREATOR = new Parcelable.Creator<Weather>() { public Weather createFromParcel(Parcel in) { return new Weather(in); } @Override public Weather[] newArray(int size) { return new Weather[size]; } }; Weather (Parcel in){ switch (in.readInt()){ case 0: units_mode = unit_system.METRIC; break; case 1: units_mode = unit_system.IMPERIAL; break; default: units_mode = unit_system.SI; } timestamp = in.readLong(); for(number nd : number.values()){ set(nd, in.readFloat()); } //add string values for(text td : text.values()){ set(td, in.readString()); } } Weather(){ timestamp = System.currentTimeMillis(); } }