List of usage examples for android.os Parcel recycle
public final void 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// ww w.j a v a 2s . c o m 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.scvngr.levelup.core.model.LoyaltyTest.java
@SmallTest public void testParcel_full() { final Loyalty loyalty = LoyaltyFixture.getFullModel(1); final Parcel parcel = Parcel.obtain(); try {//ww w .j a v a 2s . com loyalty.writeToParcel(parcel, 0); parcel.setDataPosition(0); final Loyalty parceled = Loyalty.CREATOR.createFromParcel(parcel); assertEquals(loyalty, parceled); } finally { parcel.recycle(); } }
From source file:com.scvngr.levelup.core.model.LoyaltyTest.java
@SmallTest public void testParcel_minimal() { final Loyalty loyalty = LoyaltyFixture.getMinimalModel(); final Parcel parcel = Parcel.obtain(); try {/*from w w w .jav a2 s. c om*/ loyalty.writeToParcel(parcel, 0); parcel.setDataPosition(0); final Loyalty parceled = Loyalty.CREATOR.createFromParcel(parcel); assertEquals(loyalty, parceled); } finally { parcel.recycle(); } }
From source file:org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView vHeaderId = (TextView) view.findViewById(R.id.user_id_header); TextView vName = (TextView) view.findViewById(R.id.user_id_item_name); TextView vAddresses = (TextView) view.findViewById(R.id.user_id_item_addresses); byte[] data = cursor.getBlob(1); int isHeader = cursor.getInt(2); Parcel p = Parcel.obtain(); p.unmarshall(data, 0, data.length);/*from w w w . j a va 2 s . c om*/ p.setDataPosition(0); ArrayList<String> uids = p.createStringArrayList(); p.recycle(); { // first one String userId = uids.get(0); OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId); if (splitUserId.name != null) { vName.setText(splitUserId.name); } else { vName.setText(R.string.user_id_no_name); } if (isHeader == 1) { vHeaderId.setVisibility(View.VISIBLE); String message; if (splitUserId.name != null) { message = mContext.getString(R.string.section_uids_to_certify) + splitUserId.name; } else { message = mContext.getString(R.string.section_uids_to_certify) + context.getString(R.string.user_id_no_name); } vHeaderId.setText(message); } else { vHeaderId.setVisibility(View.GONE); } } StringBuilder lines = new StringBuilder(); for (String uid : uids) { OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(uid); if (splitUserId.email == null) { continue; } lines.append(splitUserId.email); if (splitUserId.comment != null) { lines.append(" (").append(splitUserId.comment).append(")"); } lines.append('\n'); } // If we have any data here, show it if (lines.length() > 0) { // delete last newline lines.setLength(lines.length() - 1); vAddresses.setVisibility(View.VISIBLE); vAddresses.setText(lines); } else { vAddresses.setVisibility(View.GONE); } final CheckBox vCheckBox = (CheckBox) view.findViewById(R.id.user_id_item_check_box); final int position = cursor.getPosition(); vCheckBox.setOnCheckedChangeListener(null); vCheckBox.setChecked(mCheckStates.get(position)); vCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mCheckStates.set(position, b); } }); vCheckBox.setClickable(false); vCheckBox.setVisibility(checkboxVisibility ? View.VISIBLE : View.GONE); View vUidBody = view.findViewById(R.id.user_id_body); vUidBody.setClickable(true); vUidBody.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { vCheckBox.toggle(); } }); }
From source file:com.scvngr.levelup.core.model.UserTest.java
@SmallTest public void testParcel_valid() throws JSONException { final JSONObject object = UserFixture.getMinimalJsonObject(); object.remove(UserJsonFactory.JsonKeys.CUSTOM_ATTRIBUTES); final User user = new UserJsonFactory().from(object); final Parcel parcel = Parcel.obtain(); try {// w w w . j a v a 2 s .c om user.writeToParcel(parcel, 0); parcel.setDataPosition(0); final User parceled = User.CREATOR.createFromParcel(parcel); assertEquals(user, parceled); } finally { parcel.recycle(); } }
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 www . 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 {//from w w w. j av a 2 s . co m parcel.setDataPosition(0); sender.writeToParcel(parcel, 0); parcel.setDataPosition(0); return PendingIntent.CREATOR.createFromParcel(parcel); } finally { parcel.recycle(); } }
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;/* w w w . j av a2s. 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:ca.farrelltonsolar.classic.PVOutputService.java
private byte[] serializeBundle(final Bundle bundle) { byte[] rval = null; final Parcel parcel = Parcel.obtain(); try {// w ww .ja va 2s.c o m parcel.writeBundle(bundle); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(bos)); zos.write(parcel.marshall()); zos.close(); rval = bos.toByteArray(); } catch (IOException ex) { Log.w(getClass().getName(), String.format("serializeBundle failed ex: %s", ex)); } finally { parcel.recycle(); } return rval; }
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);//from w w w. ja v a 2 s . c o 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(); }