Search in sources :

Example 6 with Parcel

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)));
}
Also used : Parcel(android.os.Parcel) Parcelable(android.os.Parcelable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with Parcel

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));
}
Also used : AbsSavedState(android.view.AbsSavedState) SparseIntArray(android.util.SparseIntArray) Parcel(android.os.Parcel)

Example 8 with Parcel

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();
    }
}
Also used : Parcel(android.os.Parcel) FileOutputStream(java.io.FileOutputStream)

Example 9 with Parcel

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;
}
Also used : Parcel(android.os.Parcel)

Example 10 with Parcel

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");
    }
}
Also used : Parcel(android.os.Parcel) Bundle(android.os.Bundle)

Aggregations

Parcel (android.os.Parcel)3542 Point (android.graphics.Point)263 Test (org.junit.Test)215 SmallTest (android.test.suitebuilder.annotation.SmallTest)163 RemoteException (android.os.RemoteException)139 IBinder (android.os.IBinder)120 IOException (java.io.IOException)105 FileOutputStream (java.io.FileOutputStream)72 File (java.io.File)69 Bundle (android.os.Bundle)56 Intent (android.content.Intent)51 SmallTest (android.support.test.filters.SmallTest)51 ArrayList (java.util.ArrayList)49 ParcelFileDescriptor (android.os.ParcelFileDescriptor)35 FileInputStream (java.io.FileInputStream)34 ComponentName (android.content.ComponentName)33 KeyphraseRecognitionEvent (android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent)28 Keyphrase (android.hardware.soundtrigger.SoundTrigger.Keyphrase)24 KeyphraseSoundModel (android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel)20 Uri (android.net.Uri)20