WeatherNotification: Try to dissect the parcelable extra
This is useless, since we do not get the extra at all (only weather skins) So... this is a dead end...
This commit is contained in:
parent
483c435aa5
commit
7a1a6dbb2b
|
@ -3,15 +3,65 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class WeatherNotificationReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
|
public class WeatherNotificationReceiver extends BroadcastReceiver {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WeatherNotificationReceiver.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WeatherNotificationReceiver.class);
|
||||||
private static final int VERSION = 2;
|
|
||||||
private final String TAG = this.getClass().getSimpleName();
|
static class Weather implements Parcelable {
|
||||||
|
// getters and setters suck ;)
|
||||||
|
|
||||||
|
public long time = 0;
|
||||||
|
public long queryTime = 0;
|
||||||
|
public int version = 0;
|
||||||
|
public String location = "";
|
||||||
|
int currentTemp = 0;
|
||||||
|
|
||||||
|
private Weather(Parcel in) {
|
||||||
|
int version = in.readInt();
|
||||||
|
if (version != 2) {
|
||||||
|
LOG.info("wrong version" + version);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bundle bundle = in.readBundle();
|
||||||
|
location = bundle.getString("weather_location");
|
||||||
|
time = bundle.getLong("weather_time");
|
||||||
|
queryTime = bundle.getLong("weather_query_time");
|
||||||
|
int conditions = bundle.getInt("weather_conditions");
|
||||||
|
if (conditions > 0) {
|
||||||
|
currentTemp = bundle.getInt("weather_current_temp");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<Weather> CREATOR = new Creator<Weather>() {
|
||||||
|
@Override
|
||||||
|
public Weather createFromParcel(Parcel in) {
|
||||||
|
return new Weather(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Weather[] newArray(int size) {
|
||||||
|
return new Weather[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
// we do not really want to use this at all
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
@ -19,15 +69,22 @@ public class WeatherNotificationReceiver extends BroadcastReceiver {
|
||||||
LOG.info("Wrong action");
|
LOG.info("Wrong action");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int f = intent.getParcelableExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER");
|
Bundle bundle = intent.getExtras();
|
||||||
// int version = parcel.readInt();
|
|
||||||
// if (version != VERSION) {
|
|
||||||
// LOG.info("Wrong version");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//Bundle bundle = parcel.readBundle(this.getClass().getClassLoader());
|
for (String key : bundle.keySet()) {
|
||||||
// String location = bundle.getString("weather_location");
|
Object value = bundle.get(key);
|
||||||
// LOG.info("got location: " + location);
|
LOG.info(String.format("%s %s (%s)", key,
|
||||||
|
value.toString(), value.getClass().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!intent.hasExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER")) {
|
||||||
|
LOG.info("no weather extra");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Weather weather = intent.getParcelableExtra("ru.gelin.android.weather.notification.EXTRA_WEATHER");
|
||||||
|
if (weather != null) {
|
||||||
|
LOG.info("weather in " + weather.location + " is " + weather.currentTemp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue