use of android.os.Parcel in project jsonschema2pojo by joelittlejohn.
the class ParcelableIT method parcelableTreeIsParcelable.
@Test
public void parcelableTreeIsParcelable() throws ClassNotFoundException, IOException {
Class<?> parcelableType = schemaRule.generateAndCompile("/schema/parcelable/parcelable-schema.json", "com.example", config("parcelable", true)).loadClass("com.example.ParcelableSchema");
Parcelable instance = (Parcelable) new ObjectMapper().readValue(ParcelableIT.class.getResourceAsStream("/schema/parcelable/parcelable-data.json"), parcelableType);
String key = "example";
Parcel parcel = writeToParcel(instance, key);
Parcelable unparceledInstance = readFromParcel(parcel, parcelableType, key);
assertThat(instance, is(equalTo(unparceledInstance)));
}
use of android.os.Parcel in project Android-ObservableScrollView by ksoichiro.
the class SavedStateTest method testListViewSavedState.
public void testListViewSavedState() throws Throwable {
Parcel parcel = Parcel.obtain();
ObservableListView.SavedState state1 = new ObservableListView.SavedState(AbsSavedState.EMPTY_STATE);
state1.prevFirstVisiblePosition = 1;
state1.prevFirstVisibleChildHeight = 2;
state1.prevScrolledChildrenHeight = 3;
state1.prevScrollY = 4;
state1.scrollY = 5;
state1.childrenHeights = new SparseIntArray();
state1.childrenHeights.put(0, 10);
state1.childrenHeights.put(1, 20);
state1.childrenHeights.put(2, 30);
state1.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
ObservableListView.SavedState state2 = ObservableListView.SavedState.CREATOR.createFromParcel(parcel);
assertNotNull(state2);
assertEquals(state1.prevFirstVisiblePosition, state2.prevFirstVisiblePosition);
assertEquals(state1.prevFirstVisibleChildHeight, state2.prevFirstVisibleChildHeight);
assertEquals(state1.prevScrolledChildrenHeight, state2.prevScrolledChildrenHeight);
assertEquals(state1.prevScrollY, state2.prevScrollY);
assertEquals(state1.scrollY, state2.scrollY);
assertNotNull(state1.childrenHeights);
assertEquals(3, state1.childrenHeights.size());
assertEquals(10, state1.childrenHeights.get(0));
assertEquals(20, state1.childrenHeights.get(1));
assertEquals(30, state1.childrenHeights.get(2));
}
use of android.os.Parcel in project android_frameworks_base by ParanoidAndroid.
the class UsageStatsService method writeStatsFLOCK.
private void writeStatsFLOCK(File file) throws IOException {
FileOutputStream stream = new FileOutputStream(file);
try {
Parcel out = Parcel.obtain();
writeStatsToParcelFLOCK(out);
stream.write(out.marshall());
out.recycle();
stream.flush();
} finally {
FileUtils.sync(stream);
stream.close();
}
}
use of android.os.Parcel in project android_frameworks_base by ParanoidAndroid.
the class BatteryStatsService method getStatistics.
public byte[] getStatistics() {
mContext.enforceCallingPermission(android.Manifest.permission.BATTERY_STATS, null);
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
mStats.writeToParcel(out, 0);
byte[] data = out.marshall();
out.recycle();
return data;
}
use of android.os.Parcel in project android_frameworks_base by ParanoidAndroid.
the class SyncStorageEngine method readPendingOperationsLocked.
/**
* Read all pending operations back in to the initial engine state.
*/
private void readPendingOperationsLocked() {
if (DEBUG_FILE)
Log.v(TAG, "Reading " + mPendingFile.getBaseFile());
try {
byte[] data = mPendingFile.readFully();
Parcel in = Parcel.obtain();
in.unmarshall(data, 0, data.length);
in.setDataPosition(0);
final int SIZE = in.dataSize();
while (in.dataPosition() < SIZE) {
int version = in.readInt();
if (version != PENDING_OPERATION_VERSION && version != 1) {
Log.w(TAG, "Unknown pending operation version " + version + "; dropping all ops");
break;
}
int authorityId = in.readInt();
int syncSource = in.readInt();
byte[] flatExtras = in.createByteArray();
boolean expedited;
if (version == PENDING_OPERATION_VERSION) {
expedited = in.readInt() != 0;
} else {
expedited = false;
}
int reason = in.readInt();
AuthorityInfo authority = mAuthorities.get(authorityId);
if (authority != null) {
Bundle extras;
if (flatExtras != null) {
extras = unflattenBundle(flatExtras);
} else {
// if we are unable to parse the extras for whatever reason convert this
// to a regular sync by creating an empty extras
extras = new Bundle();
}
PendingOperation op = new PendingOperation(authority.account, authority.userId, reason, syncSource, authority.authority, extras, expedited);
op.authorityId = authorityId;
op.flatExtras = flatExtras;
if (DEBUG_FILE)
Log.v(TAG, "Adding pending op: account=" + op.account + " auth=" + op.authority + " src=" + op.syncSource + " reason=" + op.reason + " expedited=" + op.expedited + " extras=" + op.extras);
mPendingOperations.add(op);
}
}
} catch (java.io.IOException e) {
Log.i(TAG, "No initial pending operations");
}
}
Aggregations