1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Fossil Hybrid HR: experimetn with weather, does not work yet

I could change the widget icon but it always shows -- for temperature..
This commit is contained in:
Andreas Shimokawa 2020-02-16 02:19:48 +01:00
parent c57d5d3659
commit 977e94b359
3 changed files with 30 additions and 6 deletions

View File

@ -9,7 +9,6 @@ import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Build; import android.os.Build;
import android.os.CpuUsageInfo;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -37,17 +36,15 @@ import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec; import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.Transaction; import nodomain.freeyourgadget.gadgetbridge.model.Weather;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.RequestMtuRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.RequestMtuRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.SetDeviceStateRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.SetDeviceStateRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.TimeConfigItem; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.TimeConfigItem;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayCallNotificationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayCallNotificationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayTextNotificationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayTextNotificationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest;
@ -574,7 +571,30 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
.put("result", "off"); .put("result", "off");
queueWrite(new JsonPutRequest(responseObject, this)); queueWrite(new JsonPutRequest(responseObject, this));
} }
} else if (requestJson.getJSONObject("req").has("weatherInfo")) {
logger.info("Got weatherInfo request");
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec != null) {
long ts = System.currentTimeMillis();
ts /= 1000;
JSONObject responseObject = new JSONObject()
.put("res", new JSONObject()
.put("id", requestId)
.put("set", new JSONObject()
.put("weatherInfo", new JSONObject()
.put("alive", ts + 60 * 60)
.put("unit", "C") // FIXME: do not hardcode
.put("temp", weatherSpec.currentTemp - 273)
.put("cond_id", 2) // FIXME do not hardcode 2=cloudy
)
)
);
queueWrite(new JsonPutRequest(responseObject, this));
} else { } else {
logger.info("no weather data available - ignoring request");
}
} else if (requestJson.getJSONObject("req").has("commuteApp._.config.commute_info")) {
String action = requestJson.getJSONObject("req").getJSONObject("commuteApp._.config.commute_info") String action = requestJson.getJSONObject("req").getJSONObject("commuteApp._.config.commute_info")
.getString("dest"); .getString("dest");
@ -591,6 +611,8 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
Intent menuIntent = new Intent(QHybridSupport.QHYBRID_EVENT_COMMUTE_MENU); Intent menuIntent = new Intent(QHybridSupport.QHYBRID_EVENT_COMMUTE_MENU);
menuIntent.putExtra("EXTRA_ACTION", action); menuIntent.putExtra("EXTRA_ACTION", action);
getContext().sendBroadcast(menuIntent); getContext().sendBroadcast(menuIntent);
} else {
logger.warn("Unhandled request from watch: " + requestJson.toString());
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -56,6 +56,7 @@ public class Widget implements Serializable {
ACTIVE_MINUTES("activeMinutesSSE", R.string.hr_widget_active_minutes), ACTIVE_MINUTES("activeMinutesSSE", R.string.hr_widget_active_minutes),
CALORIES("caloriesSSE", R.string.hr_widget_calories), CALORIES("caloriesSSE", R.string.hr_widget_calories),
BATTERY("batterySSE", R.string.hr_widget_battery), BATTERY("batterySSE", R.string.hr_widget_battery),
WEATHER("weatherSSE", R.string.hr_widget_weather),
NOTHING(null, R.string.hr_widget_nothing); NOTHING(null, R.string.hr_widget_nothing);
private String identifier; private String identifier;

View File

@ -782,6 +782,7 @@
<string name="hr_widget_active_minutes">Active minutes</string> <string name="hr_widget_active_minutes">Active minutes</string>
<string name="hr_widget_calories">Calories</string> <string name="hr_widget_calories">Calories</string>
<string name="hr_widget_battery">Battery</string> <string name="hr_widget_battery">Battery</string>
<string name="hr_widget_weather">Weather</string>
<string name="hr_widget_nothing">Nothing</string> <string name="hr_widget_nothing">Nothing</string>
<string name="prefs_button_single_press_action_selection_title">Event 1 action</string> <string name="prefs_button_single_press_action_selection_title">Event 1 action</string>