List of usage examples for android.os Parcel obtain
public static Parcel obtain()
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 ww . java2s .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:edu.umich.flowfence.common.ParceledPayload.java
public static ParceledPayload create(Object object) { Parcel p = Parcel.obtain(); boolean oldFds = p.pushAllowFds(false); try {//from www . ja va 2 s.c o m p.writeValue(object); return new ParceledPayload(p.marshall()); } finally { p.restoreAllowFds(oldFds); p.recycle(); } }
From source file:at.bitfire.davdroid.resource.LocalGroup.java
@Override protected ContentValues contentValues() { ContentValues values = super.contentValues(); @Cleanup("recycle") Parcel members = Parcel.obtain(); members.writeStringList(contact.members); values.put(COLUMN_PENDING_MEMBERS, members.marshall()); return values; }
From source file:org.droid2droid.internal.RemoteBinderProxy.java
@Override public void dump(FileDescriptor fd, String[] args) throws RemoteException { Parcel data = Parcel.obtain(); data.writeFileDescriptor(fd);/*from w ww.j ava 2s . c om*/ data.writeStringArray(args); try { transact(DUMP_TRANSACTION, data, null, 0); } finally { data.recycle(); } }
From source file:com.android.mail.NotificationActionIntentService.java
@Override protected void onHandleIntent(final Intent intent) { final Context context = this; final String action = intent.getAction(); /*/* w ww . j a v a 2s. c o m*/ * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent * to add some extra data, it must unparcel the NotificationAction object. It throws a * ClassNotFoundException when unparcelling. * To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { LogUtils.wtf(LOG_TAG, "data was null trying to unparcel the NotificationAction"); return; } final Message message = notificationAction.getMessage(); final ContentResolver contentResolver = getContentResolver(); LogUtils.i(LOG_TAG, "Handling %s", action); logNotificationAction(action, notificationAction); if (notificationAction.getSource() == NotificationAction.SOURCE_REMOTE) { // Skip undo if the action is bridged from remote node. This should be similar to the // logic after the Undo notification expires in a regular flow. LogUtils.d(LOG_TAG, "Canceling %s", notificationAction.getNotificationId()); NotificationManagerCompat.from(context).cancel(notificationAction.getNotificationId()); NotificationActionUtils.processDestructiveAction(this, notificationAction); NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(), notificationAction.getFolder()); return; } if (ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); } else if (ACTION_ARCHIVE_REMOVE_LABEL.equals(action) || ACTION_DELETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(context, notificationAction); } else { if (ACTION_UNDO_TIMEOUT.equals(action) || ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); } else if (ACTION_MARK_READ.equals(action)) { final Uri uri = message.uri; final ContentValues values = new ContentValues(1); values.put(UIProvider.MessageColumns.READ, 1); contentResolver.update(uri, values, null, null); } NotificationActionUtils.resendNotifications(context, notificationAction.getAccount(), notificationAction.getFolder()); } }
From source file:com.granita.tasks.notification.NotificationActionIntentService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) @Override/* w w w . j a v a 2 s.c om*/ protected void onHandleIntent(Intent intent) { mAuthority = getString(R.string.org_dmfs_tasks_authority); final String action = intent.getAction(); final Context context = this; if (intent.hasExtra(EXTRA_NOTIFICATION_ID)) { Uri taskUri = intent.getData(); int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(notificationId); if (ACTION_COMPLETE.equals(action)) { markCompleted(taskUri); } else if (intent.hasExtra(EXTRA_TASK_DUE) && intent.hasExtra(EXTRA_TIMEZONE)) { long due = intent.getLongExtra(EXTRA_TASK_DUE, -1); String tz = intent.getStringExtra(EXTRA_TIMEZONE); boolean allDay = intent.getBooleanExtra(EXTRA_ALLDAY, false); if (ACTION_DELAY_1H.equals(action)) { Time time = new Time(tz); time.set(due); time.allDay = false; time.hour++; time.normalize(true); delayTask(taskUri, time); } else if (ACTION_DELAY_1D.equals(action)) { if (tz == null) { tz = "UTC"; } Time time = new Time(tz); time.set(due); time.allDay = allDay; time.monthDay++; time.normalize(true); delayTask(taskUri, time); } } } else if (intent.hasExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION)) { /* * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent to add some extra data, it must unparcel the * NotificationAction object. It throws a ClassNotFoundException when unparcelling. To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { return; } if (NotificationActionUtils.ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); resendNotification(notificationAction); } else if (ACTION_COMPLETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(this, notificationAction); } else { if (NotificationActionUtils.ACTION_UNDO_TIMEOUT.equals(action) || NotificationActionUtils.ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); processDesctructiveNotification(notificationAction); } } } }
From source file:ca.farrelltonsolar.classic.PVOutputService.java
private byte[] serializeBundle(final Bundle bundle) { byte[] rval = null; final Parcel parcel = Parcel.obtain(); try {//from w ww. ja v a2s . co 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:at.bitfire.davdroid.resource.LocalGroup.java
/** * Processes all groups with non-null {@link #COLUMN_PENDING_MEMBERS}: the pending memberships * are (if possible) applied, keeping cached memberships in sync. * @param addressBook address book to take groups from * @throws ContactsStorageException on contact provider errors */// www . j av a 2 s .c o m public static void applyPendingMemberships(LocalAddressBook addressBook) throws ContactsStorageException { try { @Cleanup Cursor cursor = addressBook.provider.query(addressBook.syncAdapterURI(Groups.CONTENT_URI), new String[] { Groups._ID, COLUMN_PENDING_MEMBERS }, COLUMN_PENDING_MEMBERS + " IS NOT NULL", new String[] {}, null); BatchOperation batch = new BatchOperation(addressBook.provider); while (cursor != null && cursor.moveToNext()) { long id = cursor.getLong(0); Constants.log.fine("Assigning members to group " + id); // delete all memberships and cached memberships for this group batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newDelete(addressBook.syncAdapterURI(ContactsContract.Data.CONTENT_URI)) .withSelection( "(" + GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?) OR (" + CachedGroupMembership.MIMETYPE + "=? AND " + CachedGroupMembership.GROUP_ID + "=?)", new String[] { GroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id), CachedGroupMembership.CONTENT_ITEM_TYPE, String.valueOf(id) }) .withYieldAllowed(true))); // extract list of member UIDs List<String> members = new LinkedList<>(); byte[] raw = cursor.getBlob(1); @Cleanup("recycle") Parcel parcel = Parcel.obtain(); parcel.unmarshall(raw, 0, raw.length); parcel.setDataPosition(0); parcel.readStringList(members); // insert memberships for (String uid : members) { Constants.log.fine("Assigning member: " + uid); try { LocalContact member = addressBook.findContactByUID(uid); member.addToGroup(batch, id); } catch (FileNotFoundException e) { Constants.log.log(Level.WARNING, "Group member not found: " + uid, e); } } // remove pending memberships batch.enqueue(new BatchOperation.Operation(ContentProviderOperation .newUpdate(addressBook.syncAdapterURI(ContentUris.withAppendedId(Groups.CONTENT_URI, id))) .withValue(COLUMN_PENDING_MEMBERS, null).withYieldAllowed(true))); batch.commit(); } } catch (RemoteException e) { throw new ContactsStorageException("Couldn't get pending memberships", e); } }
From source file:edu.umich.flowfence.common.ParceledPayload.java
public Object getValue(ClassLoader loader) { Parcel p = Parcel.obtain(); try {/*from w ww .j av a2 s.c o m*/ p.unmarshall(data, 0, data.length); p.setDataPosition(0); return p.readValue(loader); } finally { p.recycle(); } }
From source file:org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter.java
public ArrayList<CertifyAction> getSelectedCertifyActions() { LongSparseArray<CertifyAction> actions = new LongSparseArray<>(); for (int i = 0; i < mCheckStates.size(); i++) { if (mCheckStates.get(i)) { mCursor.moveToPosition(i);/*from w w w . j av a 2s. c o m*/ long keyId = mCursor.getLong(0); byte[] data = mCursor.getBlob(1); Parcel p = Parcel.obtain(); p.unmarshall(data, 0, data.length); p.setDataPosition(0); ArrayList<String> uids = p.createStringArrayList(); p.recycle(); CertifyAction action = actions.get(keyId); if (actions.get(keyId) == null) { actions.put(keyId, new CertifyAction(keyId, uids, null)); } else { action.mUserIds.addAll(uids); } } } ArrayList<CertifyAction> result = new ArrayList<>(actions.size()); for (int i = 0; i < actions.size(); i++) { result.add(actions.valueAt(i)); } return result; }