From b1a90adac9f6e2a609ce1ccd6749462bb5c9adbe Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 12 May 2016 23:33:53 -0700 Subject: altoslib: Store saved state in version-independent format Use AltosHashSet for AltosState so that AltosDroid doesn't lose tracker information when the application is upgraded. Signed-off-by: Keith Packard --- altoslib/AltosRotation.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'altoslib/AltosRotation.java') diff --git a/altoslib/AltosRotation.java b/altoslib/AltosRotation.java index 411ecbdf..e9c447ad 100644 --- a/altoslib/AltosRotation.java +++ b/altoslib/AltosRotation.java @@ -17,7 +17,7 @@ package org.altusmetrum.altoslib_11; -public class AltosRotation { +public class AltosRotation implements AltosHashable { private AltosQuaternion rotation; public double tilt() { @@ -47,4 +47,22 @@ public class AltosRotation { AltosQuaternion up = new AltosQuaternion(0, 0, 0, sky); rotation = up.vectors_to_rotation(orient); } + + public AltosHashSet hashSet() { + AltosHashSet h = new AltosHashSet(); + + h.putHashable("rotation", rotation); + return h; + } + + public AltosRotation(AltosHashSet h) { + rotation = new AltosQuaternion(h.getHash("rotation")); + } + + public static AltosRotation fromHashSet(AltosHashSet h, AltosRotation def) { + if (h == null) + return def; + + return new AltosRotation(h); + } } -- cgit v1.2.3