-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved persistent case tile load to its own detail concept. Fixed issu…
…es with lack of compartmentalization for incoming detail refs to allow mutliple refs in the same context.
- Loading branch information
Showing
9 changed files
with
124 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* | ||
*/ | ||
package org.commcare.android.util; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.commcare.android.database.DbUtil; | ||
import org.commcare.dalvik.application.CommCareApplication; | ||
import org.javarosa.core.util.externalizable.DeserializationException; | ||
import org.javarosa.core.util.externalizable.Externalizable; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
/** | ||
* @author ctsims | ||
* | ||
*/ | ||
public class SerializationUtil { | ||
public static byte[] serialize(Externalizable data) { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
try { | ||
data.writeExternal(new DataOutputStream(baos)); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException(e); | ||
} | ||
return baos.toByteArray(); | ||
} | ||
|
||
public static <T extends Externalizable> T deserialize(byte[] bytes, String name, Class<T> type) { | ||
T t; | ||
try { | ||
t = type.newInstance(); | ||
t.readExternal(new DataInputStream(new ByteArrayInputStream(bytes)), DbUtil.getPrototypeFactory(CommCareApplication._())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException(e); | ||
} catch (DeserializationException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException(e); | ||
} catch (IllegalAccessException e1) { | ||
e1.printStackTrace(); | ||
throw new RuntimeException(e1); | ||
} catch (InstantiationException e1) { | ||
e1.printStackTrace(); | ||
throw new RuntimeException(e1); | ||
} | ||
return t; | ||
} | ||
|
||
|
||
public static void serializeToIntent(Intent i, String name, Externalizable data) { | ||
i.putExtra(name, serialize(data)); | ||
} | ||
|
||
public static <T extends Externalizable> T deserializeFromIntent(Intent i, String name, Class<T> type) { | ||
if(!i.hasExtra(name)) { return null;} | ||
return deserialize(i.getByteArrayExtra(name), name, type); | ||
} | ||
|
||
public static void serializeToBundle(Bundle b, String name, Externalizable data) { | ||
b.putByteArray(name, serialize(data)); | ||
} | ||
|
||
public static <T extends Externalizable> T deserializeFromBundle(Bundle b, String name, Class<T> type) { | ||
if(!b.containsKey(name)) { return null;} | ||
return deserialize(b.getByteArray(name), name, type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.