当前位置: 首页>>代码示例>>Java>>正文


Java Parcel.setDataPosition方法代码示例

本文整理汇总了Java中android.os.Parcel.setDataPosition方法的典型用法代码示例。如果您正苦于以下问题:Java Parcel.setDataPosition方法的具体用法?Java Parcel.setDataPosition怎么用?Java Parcel.setDataPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.os.Parcel的用法示例。


在下文中一共展示了Parcel.setDataPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRestoreInstanceState

import android.os.Parcel; //导入方法依赖的package包/类
public void onRestoreInstanceState(Bundle savedInstanceState) {
    byte[] states = savedInstanceState.getByteArray(SELECTED_ITEMS_KEY);
    if ( null != states ) {
        Parcel inParcel = Parcel.obtain();
        inParcel.unmarshall(states, 0, states.length);
        inParcel.setDataPosition(0);
        mCheckStates = inParcel.readSparseBooleanArray();
        final int numStates = inParcel.readInt();
        mCheckedIdStates.clear();
        for (int i=0; i<numStates; i++) {
            final long key = inParcel.readLong();
            final int value = inParcel.readInt();
            mCheckedIdStates.put(key, value);
        }
    }
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:17,代码来源:ItemChoiceManager.java

示例2: unmarshallSerializable

import android.os.Parcel; //导入方法依赖的package包/类
/**
 * Unmarshalls a serializable's byte array into the object
 *
 * @param bytes the bytes
 * @param <T>   the type
 * @return the object
 */
@SuppressWarnings("unchecked")
public static <T extends Serializable> T unmarshallSerializable(byte[] bytes) {
    if (bytes == null) {
        return null;
    }
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);

    try {
        return (T) parcel.readSerializable();
    } catch (Exception e) {
        throw new BadParcelableException(e);
    } finally {
        parcel.recycle();
    }
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:25,代码来源:SerializationUtils.java

示例3: testWriteAndRead

import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void testWriteAndRead() {
    CredentialRetrieveRequest request = new CredentialRetrieveRequest.Builder(
            AuthenticationMethods.EMAIL)
            .setTokenProviders(ValidTokenProviderMap.make())
            .setAdditionalProperties(ValidAdditionalProperties.make())
            .setRequireUserMediation(true)
            .build();

    Parcel p = Parcel.obtain();
    try {
        request.writeToParcel(p, 0);
        p.setDataPosition(0);
        CredentialRetrieveRequest deserialized = CredentialRetrieveRequest.CREATOR.createFromParcel(p);
        assertThat(deserialized).isNotNull();
        assertThat(deserialized.getAuthenticationMethods())
                .isEqualTo(request.getAuthenticationMethods());
        ValidTokenProviderMap.assertEquals(deserialized.getTokenProviders());
        ValidAdditionalProperties.assertEquals(deserialized.getAdditionalProperties());
        assertThat(deserialized.getRequireUserMediation()).isTrue();
    } finally {
        p.recycle();
    }
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:25,代码来源:CredentialRetrieveRequestTest.java

示例4: deserializeBundle

import android.os.Parcel; //导入方法依赖的package包/类
public static Bundle deserializeBundle(final String base64) {
    Bundle bundle;

    final Parcel parcel = Parcel.obtain();
    try {
        final ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        final byte[] buffer = new byte[1024];
        final GZIPInputStream zis = new GZIPInputStream(new ByteArrayInputStream(Base64.decode(base64, 0)));
        int len;
        while ((len = zis.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }
        zis.close();
        parcel.unmarshall(byteBuffer.toByteArray(), 0, byteBuffer.size());
        parcel.setDataPosition(0);
        bundle = parcel.readBundle();
    } catch (IOException e) {
        e.printStackTrace();
        bundle = null;
    } finally {
        parcel.recycle();
    }

    return bundle;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:26,代码来源:BundleUtil.java

示例5: createFromParcel

import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void createFromParcel() throws Exception {
  String msg = "TEST";

  // Create a new item with the msg String
  QuadrantItem item = new QuadrantItem(msg);

  // Obtain a Parcel
  Parcel src = Parcel.obtain();

  // Save the item to a Parcel
  item.writeToParcel(src, 0);

  // Reset data position
  src.setDataPosition(0);

  // Create a new item from the saved Parcel
  QuadrantItem test = QuadrantItem.CREATOR.createFromParcel(src);

  // Assert that the messages are equal
  assertEquals(msg, test.getMessage());
}
 
开发者ID:Austin-Ray,项目名称:Hexis,代码行数:23,代码来源:QuadrantItemTest.java

示例6: testParcelling

import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void testParcelling() {
    PersistableBundle bundle = new PersistableBundle();
    bundle.putString("string", "string");
    bundle.putInt("int", 0);
    bundle.putLong("long", 0);
    bundle.putBoolean("boolean", true);
    // Can't use double or any array, as the instances would be different and equals() would fail.
    Parcel parcel = Parcel.obtain();
    parcel.writeValue(bundle);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    PersistableBundle parcelledBundle =
            (PersistableBundle) parcel.readValue(PersistableBundle.class.getClassLoader());

    assertEquals(bundle.toMap(1), parcelledBundle.toMap(1));
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:21,代码来源:PersistableBundleTest.java

示例7: writeToParcel

import android.os.Parcel; //导入方法依赖的package包/类
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeString(filename);
    dest.writeString(mimeType);
    dest.writeLong(modificationTime);
    dest.writeLong(originalSize);
    // version 2
    dest.writeString(charset);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:25,代码来源:SMimeMetadata.java

示例8: parcelClone

import android.os.Parcel; //导入方法依赖的package包/类
public MasterSecret parcelClone() {
  Parcel thisParcel = Parcel.obtain();
  Parcel thatParcel = Parcel.obtain();
  byte[] bytes      = null;

  thisParcel.writeValue(this);
  bytes = thisParcel.marshall();

  thatParcel.unmarshall(bytes, 0, bytes.length);
  thatParcel.setDataPosition(0);

  MasterSecret that = (MasterSecret)thatParcel.readValue(MasterSecret.class.getClassLoader());

  thisParcel.recycle();
  thatParcel.recycle();

  return that;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:19,代码来源:MasterSecret.java

示例9: save

import android.os.Parcel; //导入方法依赖的package包/类
/**
 * Saves the repeatable intent (useful for later cancelling an alarm after the application has restarted)
 *
 * @param siteToSiteRepeatableIntent the repeatable intent
 */
public void save(SiteToSiteRepeatableIntent siteToSiteRepeatableIntent) {
    Parcel parcel = Parcel.obtain();
    siteToSiteRepeatableIntent.getIntent().writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    byte[] bytes = parcel.marshall();
    SQLiteDatabase writableDatabase = sqLiteOpenHelper.getWritableDatabase();
    try {
        ContentValues contentValues = new ContentValues();
        contentValues.put(PENDING_INTENT_REQUEST_CODE, siteToSiteRepeatableIntent.getRequestCode());
        contentValues.put(CONTENT_COLUMN, bytes);
        writableDatabase.insertOrThrow(PENDING_INTENT_TABLE_NAME, null, contentValues);
    } finally {
        writableDatabase.close();
    }
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:21,代码来源:DemoAppDB.java

示例10: parcelAndUnparcel_withValidInput_returnsEquivalent

import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void parcelAndUnparcel_withValidInput_returnsEquivalent() throws Exception {
    Parcel parcel = Parcel.obtain();

    int resultCode = CredentialDeleteResult.CODE_BAD_REQUEST;
    Intent intent = CredentialDeleteResult.BAD_REQUEST.toResultDataIntent();

    // Act
    ActivityResult givenActivityResult = ActivityResult.of(resultCode, intent);
    givenActivityResult.writeToParcel(parcel, 0 /* flags */);

    parcel.setDataPosition(0);
    ActivityResult outputActivityResult = ActivityResult.CREATOR.createFromParcel(parcel);

    // Assert
    assertThat(outputActivityResult.getResultCode()).isEqualTo(resultCode);

    CredentialDeleteResult credentialDeleteResult =
            CredentialDeleteResult.fromResultIntentData(outputActivityResult.getData());
    assertThat(credentialDeleteResult.getResultCode()).isEqualTo(resultCode);
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:22,代码来源:ActivityResultTest.java

示例11: readSignature

import android.os.Parcel; //导入方法依赖的package包/类
public static void readSignature(VPackage pkg) {
    File signatureFile = VEnvironment.getSignatureFile(pkg.packageName);
    if (!signatureFile.exists()) {
        return;
    }
    Parcel p = Parcel.obtain();
    try {
        FileInputStream fis = new FileInputStream(signatureFile);
        byte[] bytes = FileUtils.toByteArray(fis);
        fis.close();
        p.unmarshall(bytes, 0, bytes.length);
        p.setDataPosition(0);
        pkg.mSignatures = p.createTypedArray(Signature.CREATOR);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:20,代码来源:PackageParserEx.java

示例12: readPendingIntent

import android.os.Parcel; //导入方法依赖的package包/类
public static PendingIntent readPendingIntent(IBinder binder) {
    Parcel parcel = Parcel.obtain();
    parcel.writeStrongBinder(binder);
    parcel.setDataPosition(0);
    try {
        return PendingIntent.readPendingIntentOrNullFromParcel(parcel);
    } finally {
        parcel.recycle();
    }
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:11,代码来源:PendingIntentData.java

示例13: testWriteAndReadParcel_noResponseMessage

import android.os.Parcel; //导入方法依赖的package包/类
@Test
public void testWriteAndReadParcel_noResponseMessage() {
    QueryResponse queryResponse = new QueryResponse(PACKAGE, RESPONSE_ID, null);
    Parcel p = Parcel.obtain();
    p.writeParcelable(queryResponse, 0);
    p.setDataPosition(0);
    QueryResponse read = p.readParcelable(QueryResponse.class.getClassLoader());

    assertThat(read.responderPackage).isEqualTo(QUERY_RESPONSE.responderPackage);
    assertThat(read.responseId).isEqualTo(QUERY_RESPONSE.responseId);
    assertThat(read.responseMessage).isNull();
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:13,代码来源:QueryResponseTest.java

示例14: createFromParcel

import android.os.Parcel; //导入方法依赖的package包/类
public MediaMetadata createFromParcel(Parcel p) {
    MediaMetadata metadata = new MediaMetadata();
    Parcel data = Parcel.obtain();

    data.appendFrom(p, p.dataPosition(), p.dataAvail());
    data.setDataPosition(0);
    if (metadata.parse(data))
        return metadata;
    else
        return null;
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:12,代码来源:MediaMetadata.java

示例15: bytes2Parcelable

import android.os.Parcel; //导入方法依赖的package包/类
private static <T> T bytes2Parcelable(byte[] bytes, Parcelable.Creator<T> creator) {
    if (bytes == null) return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:10,代码来源:CacheUtils.java


注:本文中的android.os.Parcel.setDataPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。