-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow object creation using SafeParcelUtil and add AutoSafeParcelable
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.microg.safeparcel; | ||
|
||
import android.os.Parcel; | ||
|
||
import java.lang.reflect.Array; | ||
|
||
public abstract class AutoSafeParcelable implements SafeParcelable { | ||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel out, int flags) { | ||
SafeParcelUtil.writeObject(this, out, flags); | ||
} | ||
|
||
public static class AutoCreator<T extends SafeParcelable> implements Creator<T> { | ||
|
||
private Class<T> tClass; | ||
|
||
public AutoCreator(Class<T> tClass) { | ||
this.tClass = tClass; | ||
} | ||
|
||
@Override | ||
public T createFromParcel(Parcel parcel) { | ||
return SafeParcelUtil.createObject(tClass, parcel); | ||
} | ||
|
||
@Override | ||
public T[] newArray(int i) { | ||
return (T[]) Array.newInstance(tClass, i); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters