mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-09 13:43:22 +00:00
86 lines
3.2 KiB
Java
86 lines
3.2 KiB
Java
package androidx.versionedparcelable;
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class ParcelUtils {
|
|
private static final String INNER_BUNDLE_KEY = "a";
|
|
|
|
private ParcelUtils() {
|
|
}
|
|
|
|
public static Parcelable toParcelable(VersionedParcelable versionedParcelable) {
|
|
return new ParcelImpl(versionedParcelable);
|
|
}
|
|
|
|
public static <T extends VersionedParcelable> T fromParcelable(Parcelable parcelable) {
|
|
if (!(parcelable instanceof ParcelImpl)) {
|
|
throw new IllegalArgumentException("Invalid parcel");
|
|
}
|
|
return (T) ((ParcelImpl) parcelable).getVersionedParcel();
|
|
}
|
|
|
|
public static void toOutputStream(VersionedParcelable versionedParcelable, OutputStream outputStream) {
|
|
VersionedParcelStream versionedParcelStream = new VersionedParcelStream(null, outputStream);
|
|
versionedParcelStream.writeVersionedParcelable(versionedParcelable);
|
|
versionedParcelStream.closeField();
|
|
}
|
|
|
|
public static <T extends VersionedParcelable> T fromInputStream(InputStream inputStream) {
|
|
return (T) new VersionedParcelStream(inputStream, null).readVersionedParcelable();
|
|
}
|
|
|
|
public static void putVersionedParcelable(Bundle bundle, String str, VersionedParcelable versionedParcelable) {
|
|
if (versionedParcelable == null) {
|
|
return;
|
|
}
|
|
Bundle bundle2 = new Bundle();
|
|
bundle2.putParcelable("a", toParcelable(versionedParcelable));
|
|
bundle.putParcelable(str, bundle2);
|
|
}
|
|
|
|
public static <T extends VersionedParcelable> T getVersionedParcelable(Bundle bundle, String str) {
|
|
try {
|
|
Bundle bundle2 = (Bundle) bundle.getParcelable(str);
|
|
if (bundle2 == null) {
|
|
return null;
|
|
}
|
|
bundle2.setClassLoader(ParcelUtils.class.getClassLoader());
|
|
return (T) fromParcelable(bundle2.getParcelable("a"));
|
|
} catch (RuntimeException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static void putVersionedParcelableList(Bundle bundle, String str, List<? extends VersionedParcelable> list) {
|
|
Bundle bundle2 = new Bundle();
|
|
ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
|
|
Iterator<? extends VersionedParcelable> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
arrayList.add(toParcelable(it.next()));
|
|
}
|
|
bundle2.putParcelableArrayList("a", arrayList);
|
|
bundle.putParcelable(str, bundle2);
|
|
}
|
|
|
|
public static <T extends VersionedParcelable> List<T> getVersionedParcelableList(Bundle bundle, String str) {
|
|
ArrayList arrayList = new ArrayList();
|
|
try {
|
|
Bundle bundle2 = (Bundle) bundle.getParcelable(str);
|
|
bundle2.setClassLoader(ParcelUtils.class.getClassLoader());
|
|
Iterator it = bundle2.getParcelableArrayList("a").iterator();
|
|
while (it.hasNext()) {
|
|
arrayList.add(fromParcelable((Parcelable) it.next()));
|
|
}
|
|
return arrayList;
|
|
} catch (RuntimeException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
}
|