2020-01-09 10:44:32 +01:00
|
|
|
/* Copyright (C) 2016-2020 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2018-06-25 18:35:46 +02:00
|
|
|
Gobbetti
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2020-10-01 13:56:03 +02:00
|
|
|
|
2016-12-31 15:56:05 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.model;
|
|
|
|
|
2017-11-29 23:57:36 +01:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
|
2022-08-18 23:03:28 +02:00
|
|
|
import java.io.Serializable;
|
2017-11-29 23:57:36 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2017-10-12 23:25:26 +02:00
|
|
|
// FIXME: document me and my fields, including units
|
2022-08-18 23:03:28 +02:00
|
|
|
public class WeatherSpec implements Parcelable, Serializable {
|
|
|
|
|
2017-11-29 23:57:36 +01:00
|
|
|
public static final Creator<WeatherSpec> CREATOR = new Creator<WeatherSpec>() {
|
|
|
|
@Override
|
|
|
|
public WeatherSpec createFromParcel(Parcel in) {
|
|
|
|
return new WeatherSpec(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WeatherSpec[] newArray(int size) {
|
|
|
|
return new WeatherSpec[size];
|
|
|
|
}
|
|
|
|
};
|
2020-10-01 13:56:03 +02:00
|
|
|
public static final int VERSION = 2;
|
2022-08-18 23:03:28 +02:00
|
|
|
private static final long serialVersionUID = VERSION;
|
2016-12-31 15:56:05 +01:00
|
|
|
public int timestamp;
|
|
|
|
public String location;
|
|
|
|
public int currentTemp;
|
2017-11-30 10:24:31 +01:00
|
|
|
public int currentConditionCode = 3200;
|
2016-12-31 15:56:05 +01:00
|
|
|
public String currentCondition;
|
2017-12-14 14:54:09 +01:00
|
|
|
public int currentHumidity;
|
2016-12-31 15:56:05 +01:00
|
|
|
public int todayMaxTemp;
|
|
|
|
public int todayMinTemp;
|
2018-04-14 19:42:05 +02:00
|
|
|
public float windSpeed; //km per hour
|
|
|
|
public int windDirection; //deg
|
|
|
|
|
2017-11-29 23:57:36 +01:00
|
|
|
public ArrayList<Forecast> forecasts = new ArrayList<>();
|
|
|
|
|
|
|
|
public WeatherSpec() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-21 17:12:20 +02:00
|
|
|
// Lower bounds of beaufort regions 1 to 12
|
|
|
|
// Values from https://en.wikipedia.org/wiki/Beaufort_scale
|
|
|
|
static final float[] beaufort = new float[] { 2, 6, 12, 20, 29, 39, 50, 62, 75, 89, 103, 118 };
|
|
|
|
// level: 0 1 2 3 4 5 6 7 8 9 10 11 12
|
|
|
|
|
|
|
|
public int windSpeedAsBeaufort() {
|
|
|
|
int l = 0;
|
|
|
|
while (l < beaufort.length && beaufort[l] < this.windSpeed) {
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2017-11-29 23:57:36 +01:00
|
|
|
protected WeatherSpec(Parcel in) {
|
2020-10-01 13:56:03 +02:00
|
|
|
int version = in.readInt();
|
|
|
|
if (version == VERSION) {
|
|
|
|
timestamp = in.readInt();
|
|
|
|
location = in.readString();
|
|
|
|
currentTemp = in.readInt();
|
|
|
|
currentConditionCode = in.readInt();
|
|
|
|
currentCondition = in.readString();
|
|
|
|
currentHumidity = in.readInt();
|
|
|
|
todayMaxTemp = in.readInt();
|
|
|
|
todayMinTemp = in.readInt();
|
|
|
|
windSpeed = in.readFloat();
|
|
|
|
windDirection = in.readInt();
|
|
|
|
in.readList(forecasts, Forecast.class.getClassLoader());
|
|
|
|
}
|
2017-11-29 23:57:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
2020-10-01 13:56:03 +02:00
|
|
|
dest.writeInt(VERSION);
|
2017-11-29 23:57:36 +01:00
|
|
|
dest.writeInt(timestamp);
|
|
|
|
dest.writeString(location);
|
|
|
|
dest.writeInt(currentTemp);
|
|
|
|
dest.writeInt(currentConditionCode);
|
|
|
|
dest.writeString(currentCondition);
|
2017-12-14 14:54:09 +01:00
|
|
|
dest.writeInt(currentHumidity);
|
2017-11-29 23:57:36 +01:00
|
|
|
dest.writeInt(todayMaxTemp);
|
|
|
|
dest.writeInt(todayMinTemp);
|
2020-10-01 13:56:03 +02:00
|
|
|
dest.writeFloat(windSpeed);
|
|
|
|
dest.writeInt(windDirection);
|
2017-11-29 23:57:36 +01:00
|
|
|
dest.writeList(forecasts);
|
|
|
|
}
|
|
|
|
|
2022-08-18 23:03:28 +02:00
|
|
|
public static class Forecast implements Parcelable, Serializable {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
2017-11-29 23:57:36 +01:00
|
|
|
public static final Creator<Forecast> CREATOR = new Creator<Forecast>() {
|
|
|
|
@Override
|
|
|
|
public Forecast createFromParcel(Parcel in) {
|
|
|
|
return new Forecast(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Forecast[] newArray(int size) {
|
|
|
|
return new Forecast[size];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public int minTemp;
|
|
|
|
public int maxTemp;
|
|
|
|
public int conditionCode;
|
2017-12-14 14:54:09 +01:00
|
|
|
public int humidity;
|
2017-11-29 23:57:36 +01:00
|
|
|
|
|
|
|
public Forecast() {
|
|
|
|
}
|
|
|
|
|
2017-12-14 14:54:09 +01:00
|
|
|
public Forecast(int minTemp, int maxTemp, int conditionCode, int humidity) {
|
2017-11-29 23:57:36 +01:00
|
|
|
this.minTemp = minTemp;
|
|
|
|
this.maxTemp = maxTemp;
|
|
|
|
this.conditionCode = conditionCode;
|
2017-12-14 14:54:09 +01:00
|
|
|
this.humidity = humidity;
|
2017-11-29 23:57:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Forecast(Parcel in) {
|
|
|
|
minTemp = in.readInt();
|
|
|
|
maxTemp = in.readInt();
|
|
|
|
conditionCode = in.readInt();
|
2017-12-14 14:54:09 +01:00
|
|
|
humidity = in.readInt();
|
2017-11-29 23:57:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeInt(minTemp);
|
|
|
|
dest.writeInt(maxTemp);
|
|
|
|
dest.writeInt(conditionCode);
|
2017-12-14 14:54:09 +01:00
|
|
|
dest.writeInt(humidity);
|
2017-11-29 23:57:36 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-31 15:56:05 +01:00
|
|
|
}
|