List of usage examples for android.os Parcel setDataPosition
public final void setDataPosition(int pos)
From source file:com.facebook.TestUtils.java
public static <E extends Parcelable> E parcelAndUnparcel(final E object) { final Parcel writeParcel = Parcel.obtain(); final Parcel readParcel = Parcel.obtain(); try {/* w w w . ja v a 2s. c o m*/ writeParcel.writeParcelable(object, 0); final byte[] bytes = writeParcel.marshall(); readParcel.unmarshall(bytes, 0, bytes.length); readParcel.setDataPosition(0); return readParcel.readParcelable(object.getClass().getClassLoader()); } finally { writeParcel.recycle(); readParcel.recycle(); } }
From source file:com.marianhello.bgloc.Config.java
public static Config fromByteArray(byte[] byteArray) { Parcel parcel = Parcel.obtain(); parcel.unmarshall(byteArray, 0, byteArray.length); parcel.setDataPosition(0); return Config.CREATOR.createFromParcel(parcel); }
From source file:com.granita.tasks.notification.NotificationActionUtils.java
/** * <p>/* w w w .jav a 2 s.co m*/ * This is a slight hack to avoid an exception in the remote AlarmManagerService process. The AlarmManager adds extra data to this Intent which causes it to * inflate. Since the remote process does not know about the NotificationAction class, it throws a ClassNotFoundException. * </p> * <p> * To avoid this, we marshall the data ourselves and then parcel a plain byte[] array. The NotificationActionIntentService class knows to build the * NotificationAction object from the byte[] array. * </p> */ private static void putNotificationActionExtra(final Intent intent, final NotificationAction notificationAction) { final Parcel out = Parcel.obtain(); notificationAction.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(EXTRA_NOTIFICATION_ACTION, out.marshall()); }
From source file:com.smarthome.deskclock.Alarms.java
/** * Sets alert in AlarmManger and StatusBar. This is what will * actually launch the alert when the alarm triggers. * * @param alarm Alarm.// w w w .ja va 2s . c om * @param atTimeInMillis milliseconds since epoch */ private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Log.LOGV) { Log.v("** setAlert id " + alarm.id + " atTime " + atTimeInMillis); } Intent intent = new Intent(ALARM_ALERT_ACTION); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the Alarm class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The AlarmReceiver class knows to build the Alarm // object from the byte[] array. Parcel out = Parcel.obtain(); alarm.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(ALARM_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); setStatusBarIcon(context, true); Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }
From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java
/** * Sets action in AlarmManger. This is what will * actually launch the action when the schedule triggers. * * @param schedule TimeSchedule.//from w w w. j av a 2 s.c o m * @param atTimeInMillis milliseconds since epoch */ @SuppressLint("NewApi") private static void enableAction(Context context, final TimeSchedule schedule, final long atTimeInMillis) { if (Log.LOGV) { Log.v("** setSchedule id " + schedule.id + " atTime " + atTimeInMillis); } Intent intent = new Intent(EXECUTE_SCHEDULE_ACTION); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the TimeSchedule class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The ScheduleReceiver class knows to build the TimeSchedule // object from the byte[] array. Parcel out = Parcel.obtain(); schedule.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(INTENT_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, schedule.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (Utils.isKitKatOrLater()) { am.setExact(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); } else { am.set(AlarmManager.RTC_WAKEUP, atTimeInMillis, sender); } Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }
From source file:com.jungle.base.utils.MiscUtils.java
public static Bundle bytesToBundle(byte[] bytes) { Bundle bundle = new Bundle(); if (bytes == null || bytes.length == 0) { return bundle; }//from w w w. j a v a2s . c om Parcel accountInfoParcel = Parcel.obtain(); accountInfoParcel.unmarshall(bytes, 0, bytes.length); accountInfoParcel.setDataPosition(0); bundle.readFromParcel(accountInfoParcel); accountInfoParcel.recycle(); return bundle; }
From source file:com.android.mail.utils.NotificationActionUtils.java
/** * <p>/*from w w w . j ava 2s. c om*/ * This is a slight hack to avoid an exception in the remote AlarmManagerService process. The * AlarmManager adds extra data to this Intent which causes it to inflate. Since the remote * process does not know about the NotificationAction class, it throws a ClassNotFoundException. * </p> * <p> * To avoid this, we marshall the data ourselves and then parcel a plain byte[] array. The * NotificationActionIntentService class knows to build the NotificationAction object from the * byte[] array. * </p> */ private static void putNotificationActionExtra(final Intent intent, final NotificationAction notificationAction) { final Parcel out = Parcel.obtain(); notificationAction.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(NotificationActionIntentService.EXTRA_NOTIFICATION_ACTION, out.marshall()); }
From source file:com.clover.sdk.v3.apps.AppNotificationTest.java
/** * Tests serializing to and from a {@code Parcel}. *///from w w w. j a v a2 s . c om public void testParcelable() throws Exception { AppNotification expected = new AppNotification("sale", "Sunday"); Parcel p = Parcel.obtain(); expected.writeToParcel(p, 0); p.setDataPosition(0); AppNotification actual = AppNotification.CREATOR.createFromParcel(p); Assert.assertEquals(expected, actual); }
From source file:com.scvngr.levelup.core.model.LocationTest.java
@SmallTest public void testParcel() throws JSONException { final JSONObject object = LocationFixture.getFullJsonObject(); final Location location = new LocationJsonFactory().from(object); final Parcel parcel = Parcel.obtain(); location.writeToParcel(parcel, 0);/*from w ww .ja va 2 s . c om*/ parcel.setDataPosition(0); final Location parceled = Location.CREATOR.createFromParcel(parcel); assertEquals(location, parceled); parcel.recycle(); }
From source file:com.scvngr.levelup.core.model.CampaignTest.java
@SmallTest public void testParcel() throws JSONException { {//from w w w . j a v a 2s.c o m final JSONObject object = CampaignFixture.getFullJsonObject(); final Campaign campaign = new CampaignJsonFactory().from(object); final Parcel parcel = Parcel.obtain(); campaign.writeToParcel(parcel, 0); parcel.setDataPosition(0); final Campaign parceled = Campaign.CREATOR.createFromParcel(parcel); assertEquals(campaign, parceled); } }