List of usage examples for android.os Parcel recycle
public final void recycle()
From source file:Main.java
/** * Returns a cached instance if such is available or a new one is created. * The returned instance is initialized from the given <code>event</code>. * * @param event The other event./*from www.j a v a 2s. c om*/ * @return An instance. */ public static AccessibilityEvent obtain(AccessibilityEvent event) { final Parcel parcel = Parcel.obtain(); // Write the event to the parcel and reset the data pointer. event.writeToParcel(parcel, 0); parcel.setDataPosition(0); final AccessibilityEvent clone = AccessibilityEvent.CREATOR.createFromParcel(parcel); // Return the parcel to the global pool. parcel.recycle(); return clone; }
From source file:edu.umich.flowfence.common.ParceledPayload.java
public static boolean canParcelObject(Object obj) { Parcel p = Parcel.obtain(); try {//from w w w . ja va 2 s . c o m p.writeValue(obj); return true; } catch (Exception e) { return false; } finally { p.recycle(); } }
From source file:hochschuledarmstadt.photostream_tools.Fakes.java
public static Photo buildFakePhoto(int id, String filePath, String desc, boolean liked, boolean deleteable, int commentCount) { Parcel source = Parcel.obtain(); source.writeInt(id);/*from ww w.j a v a 2s. c o m*/ source.writeString(filePath); source.writeString(desc); source.writeInt(liked ? 1 : 0); source.writeInt(deleteable ? 1 : 0); source.writeInt(commentCount); source.setDataPosition(0); Photo photo = Photo.CREATOR.createFromParcel(source); source.recycle(); return photo; }
From source file:com.oasisfeng.android.service.notification.StatusBarNotificationCompat.java
private static UserHandle toUserHandle(final int user) { final Parcel parcel = Parcel.obtain(); try {// w w w . j av a 2s . c om parcel.writeInt(user); parcel.setDataPosition(0); return UserHandle.readFromParcel(parcel); } finally { parcel.recycle(); } }
From source file:Main.java
public static ContentValues[] arrayContentValuesFromByteArray(byte[] byteArray) { Parcel obtain = Parcel.obtain(); obtain.unmarshall(byteArray, 0, byteArray.length); obtain.setDataPosition(0);/* ww w. j av a 2s .c o m*/ Parcelable[] contentValues = obtain.readParcelableArray(ContentValues.class.getClassLoader()); ContentValues[] values = new ContentValues[contentValues.length]; for (int i = 0; i < contentValues.length; i++) { values[i] = (ContentValues) contentValues[i]; } obtain.recycle(); return values; }
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 {/*www . j a v a2s . co m*/ p.writeValue(object); return new ParceledPayload(p.marshall()); } finally { p.restoreAllowFds(oldFds); p.recycle(); } }
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 {/*from w ww . j a va2 s . com*/ 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:Main.java
/** * Repairs the broken tag on HTC devices running Android 5.x * <p/>//from ww w .j a v a2s . c o m * "It seems, the reason of this bug in TechExtras of NfcA is null. However, TechList contains MifareClassic." -bildin * For more information please refer to https://github.com/ikarus23/MifareClassicTool/issues/52#issuecomment-103797115 * <p/> * Code source: https://github.com/ikarus23/MifareClassicTool/issues/52#issuecomment-104277445 * * @param oTag The broken tag * @return The fixed tag */ public static Tag repairTag(Tag oTag) { if (oTag == null) return null; String[] sTechList = oTag.getTechList(); Parcel oParcel, nParcel; oParcel = Parcel.obtain(); oTag.writeToParcel(oParcel, 0); oParcel.setDataPosition(0); int len = oParcel.readInt(); byte[] id = null; if (len >= 0) { id = new byte[len]; oParcel.readByteArray(id); } int[] oTechList = new int[oParcel.readInt()]; oParcel.readIntArray(oTechList); Bundle[] oTechExtras = oParcel.createTypedArray(Bundle.CREATOR); int serviceHandle = oParcel.readInt(); int isMock = oParcel.readInt(); IBinder tagService; if (isMock == 0) { tagService = oParcel.readStrongBinder(); } else { tagService = null; } oParcel.recycle(); int nfca_idx = -1; int mc_idx = -1; for (int idx = 0; idx < sTechList.length; idx++) { if (sTechList[idx].equals(NfcA.class.getName())) { nfca_idx = idx; } else if (sTechList[idx].equals(MifareClassic.class.getName())) { mc_idx = idx; } } if (nfca_idx >= 0 && mc_idx >= 0 && oTechExtras[mc_idx] == null) { oTechExtras[mc_idx] = oTechExtras[nfca_idx]; } else { return oTag; } nParcel = Parcel.obtain(); nParcel.writeInt(id.length); nParcel.writeByteArray(id); nParcel.writeInt(oTechList.length); nParcel.writeIntArray(oTechList); nParcel.writeTypedArray(oTechExtras, 0); nParcel.writeInt(serviceHandle); nParcel.writeInt(isMock); if (isMock == 0) { nParcel.writeStrongBinder(tagService); } nParcel.setDataPosition(0); Tag nTag = Tag.CREATOR.createFromParcel(nParcel); nParcel.recycle(); return nTag; }
From source file:com.jungle.base.utils.MiscUtils.java
public static byte[] bundleToBytes(Bundle bundle) { Parcel accountInfoParcel = Parcel.obtain(); bundle.writeToParcel(accountInfoParcel, 0); byte[] bytes = accountInfoParcel.marshall(); accountInfoParcel.recycle(); return bytes; }
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 va 2s. com*/ Parcel accountInfoParcel = Parcel.obtain(); accountInfoParcel.unmarshall(bytes, 0, bytes.length); accountInfoParcel.setDataPosition(0); bundle.readFromParcel(accountInfoParcel); accountInfoParcel.recycle(); return bundle; }