List of usage examples for android.os Parcel obtain
public static Parcel obtain()
From source file:ca.farrelltonsolar.classic.PVOutputUploader.java
private Bundle deserializeBundle(byte[] data) { Bundle bundle = null;//from w w w. j ava 2 s . c o m final Parcel parcel = Parcel.obtain(); try { final ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); final byte[] buffer = new byte[1024]; final GZIPInputStream zis = new GZIPInputStream(new ByteArrayInputStream(data)); int len = 0; 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 ex) { Log.w(getClass().getName(), String.format("deserializeBundle failed ex: %s", ex)); bundle = null; } finally { parcel.recycle(); } return bundle; }
From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java
/** Send transactions to remote cloud. */ @Override// ww w . j a v a 2s.c o m public int bindOID(int connid, int serviceConnectionOID, Intent intent, int flags, ComponentName[] name, long timeout) throws RemoteException { if (D) Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "BindOID..."); Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { data.writeInt(serviceConnectionOID); NormalizeIntent.writeIntent(intent, data, 0); data.writeInt(flags); transactRemoteAndroid(connid, BIND_OID, data, reply, 0, timeout); if (D) Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "BindOID ok"); name[0] = (ComponentName) reply.readParcelable(ComponentName.class.getClassLoader()); return reply.readInt(); } finally { if (data != null) data.recycle(); if (reply != null) reply.recycle(); } }
From source file:org.sufficientlysecure.keychain.ui.MultiUserIdsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { MatrixCursor matrix = new MatrixCursor(new String[] { "_id", "user_data", "grouped" }) { @Override/*from w w w . j a va 2 s .c om*/ public byte[] getBlob(int column) { return super.getBlob(column); } }; data.moveToFirst(); long lastMasterKeyId = 0; String lastName = ""; ArrayList<String> uids = new ArrayList<>(); boolean header = true; // Iterate over all rows while (!data.isAfterLast()) { long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID); String userId = data.getString(INDEX_USER_ID); OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId); // Two cases: boolean grouped = masterKeyId == lastMasterKeyId; boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name); // Remember for next loop lastName = pieces.name; Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped")); if (!subGrouped) { // 1. This name should NOT be grouped with the previous, so we flush the buffer Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); // indicate that we have a header for this masterKeyId header = false; // Now clear the buffer, and add the new user id, for the next round uids.clear(); } // 2. This name should be grouped with the previous, just add to buffer uids.add(userId); lastMasterKeyId = masterKeyId; // If this one wasn't grouped, the next one's gotta be a header if (!grouped) { header = true; } // Regardless of the outcome, move to next entry data.moveToNext(); } // If there is anything left in the buffer, flush it one last time if (!uids.isEmpty()) { Parcel p = Parcel.obtain(); p.writeStringList(uids); byte[] d = p.marshall(); p.recycle(); matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 }); } mUserIdsAdapter.swapCursor(matrix); }
From source file:com.android.emailcommon.provider.HostAuthTests.java
public void testParceling() { final HostAuth orig = new HostAuth(); // Fill in some data orig.mPort = 993;/*from w w w .ja v a 2 s.c o m*/ orig.mProtocol = "imap"; orig.mAddress = "example.com"; orig.mLogin = "user"; orig.mPassword = "supersecret"; orig.mDomain = "domain"; orig.mClientCertAlias = "certalias"; final Parcel p1 = Parcel.obtain(); orig.writeToParcel(p1, 0); p1.setDataPosition(0); final HostAuth unparceled1 = new HostAuth(p1); p1.recycle(); assertEquals(orig, unparceled1); assertEquals(orig.mCredentialKey, unparceled1.mCredentialKey); assertEquals(orig.mCredential, unparceled1.mCredential); orig.getOrCreateCredential(new MockContext()); final Parcel p2 = Parcel.obtain(); orig.writeToParcel(p2, 0); p2.setDataPosition(0); final HostAuth unparceled2 = new HostAuth(p2); p2.recycle(); assertEquals(orig, unparceled2); assertEquals(orig.mCredentialKey, unparceled2.mCredentialKey); assertEquals(orig.mCredential, unparceled2.mCredential); }
From source file:com.oasisfeng.nevo.decorators.media.MediaPlayerDecorator.java
/** Tiny hack to convert IntentSender to PendingIntent */ PendingIntent getPendingIntent(final IntentSender sender) { final Parcel parcel = Parcel.obtain(); try {//ww w .j ava 2 s. c o m parcel.setDataPosition(0); sender.writeToParcel(parcel, 0); parcel.setDataPosition(0); return PendingIntent.CREATOR.createFromParcel(parcel); } finally { parcel.recycle(); } }
From source file:app.com.example.android.sunshine.ItemChoiceManager.java
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);// w w w .j a va2s . co m 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); } } }
From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java
@Override public boolean unbindService(ServiceConnection conn) { synchronized (mBinders) { Binded binder = mBinders.get(conn); if (binder != null) { if (D) Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "UnBindOID..."); Parcel data = Parcel.obtain(); Parcel reply = Parcel.obtain(); try { try { data.writeInt(System.identityHashCode(conn)); transactRemoteAndroid(getConnectionId(), UNBIND_SRV, data, reply, 0, mExecuteTimeout); if (D) Log.d(TAG_CLIENT_BIND, PREFIX_LOG + "UnBindOID ok"); } catch (RemoteException e) { if (W && !D) Log.w(TAG_CLIENT_BIND, "Error when unbind (" + e.getMessage() + ")"); if (D) Log.w(TAG_CLIENT_BIND, "Errer when unbind", e); }//from w ww . j a v a 2 s. c o m } finally { if (data != null) data.recycle(); if (reply != null) reply.recycle(); } mBinders.remove(conn); } else return false; } return true; }
From source file:org.thoughtcrime.securesms.ShareActivity.java
private void handleResolvedMedia(Intent intent, boolean animate) { long threadId = intent.getLongExtra(EXTRA_THREAD_ID, -1); int distributionType = intent.getIntExtra(EXTRA_DISTRIBUTION_TYPE, -1); Address address = null;/*from w w w.jav a 2 s .c o m*/ if (intent.hasExtra(EXTRA_ADDRESS_MARSHALLED)) { Parcel parcel = Parcel.obtain(); byte[] marshalled = intent.getByteArrayExtra(EXTRA_ADDRESS_MARSHALLED); parcel.unmarshall(marshalled, 0, marshalled.length); parcel.setDataPosition(0); address = parcel.readParcelable(getClassLoader()); parcel.recycle(); } boolean hasResolvedDestination = threadId != -1 && address != null && distributionType != -1; if (!hasResolvedDestination && animate) { ViewUtil.fadeIn(contactsFragment.getView(), 300); ViewUtil.fadeOut(progressWheel, 300); } else if (!hasResolvedDestination) { contactsFragment.getView().setVisibility(View.VISIBLE); progressWheel.setVisibility(View.GONE); } else { createConversation(threadId, address, distributionType); } }
From source file:app.com.example.android.sunshine.ItemChoiceManager.java
public void onSaveInstanceState(Bundle outState) { Parcel outParcel = Parcel.obtain(); outParcel.writeSparseBooleanArray(mCheckStates); final int numStates = mCheckedIdStates.size(); outParcel.writeInt(numStates);//ww w . ja v a 2 s . co m for (int i = 0; i < numStates; i++) { outParcel.writeLong(mCheckedIdStates.keyAt(i)); outParcel.writeInt(mCheckedIdStates.valueAt(i)); } byte[] states = outParcel.marshall(); outState.putByteArray(SELECTED_ITEMS_KEY, states); outParcel.recycle(); }
From source file:com.harlie.android.sunshine.app.ItemChoiceManager.java
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);//from w w w .ja v a 2s . c o m 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); } inParcel.recycle(); } }