ruffy: take over Menu changes (robustness, presumably), from 46e92833.

This commit is contained in:
Johannes Mockenhaupt 2017-10-18 23:23:26 +02:00
parent 51aceadfb1
commit d9235cf54b
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -2,6 +2,7 @@ package org.monkey.d.ruffy.ruffy.driver.display;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import org.monkey.d.ruffy.ruffy.driver.display.menu.BolusType;
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuBlink;
@ -17,7 +18,7 @@ import java.util.Map;
* Created by fishermen21 on 20.05.17.
*/
public class Menu implements Parcelable {
public class Menu implements Parcelable{
private MenuType type;
private Map<MenuAttribute,Object> attributes = new HashMap<>();
@ -34,6 +35,7 @@ public class Menu implements Parcelable {
String clas = in.readString();
String value = in.readString();
if(attr!=null && clas!=null && value!=null) {
MenuAttribute a = MenuAttribute.valueOf(attr);
Object o = null;
if (Integer.class.toString().equals(clas)) {
@ -52,16 +54,24 @@ public class Menu implements Parcelable {
o = BolusType.valueOf(value);
} else if (String.class.toString().equals(clas)) {
o = new String(value);
} else {
Log.e("MENU","unknown class: "+clas);
}
if (o != null) {
attributes.put(a, o);
} else {
// Log.e("MenuIn", "failed to parse: " + attr + " / " + clas + " / " + value);
Log.e("MenuIn", "failed to parse: " + attr + " / " + clas + " / " + value);
}
}
else
{
Log.e("MenuIn", "failed to parse: " + attr + " / " + clas + " / " + value);
}
}catch(Exception e)
{
// Log.e("MenuIn","Exception in read",e);
Log.e("MenuIn","Exception in read",e);
}
}
@ -98,14 +108,23 @@ public class Menu implements Parcelable {
{
try
{
dest.writeString(a.toString());
Object o = attributes.get(a);
dest.writeString(o.getClass().toString());
dest.writeString(o.toString());
String atr = a.toString();
Object o = attributes.get(a);
String clas = o.getClass().toString();
String v = o.toString();
if(atr != null && o != null && v != null) {
dest.writeString(atr);
dest.writeString(clas);
dest.writeString(v);
}
else
{
Log.e("Menu","null in write :/");
}
}catch(Exception e)
{
// Log.v("MenuOut","error in write",e);
Log.v("MenuOut","error in write",e);
}
}
}