Android Open Source - demo-app-android Parcel Utils






From Project

Back to project page demo-app-android.

License

The source code is released under:

MIT License

If you think the Android project demo-app-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.rong.imkit.demo;
//  w w  w.ja  v a  2s  .c  om
import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;


public class ParcelUtils {

    final static int EXIST_SEPARATOR = 1;
    final static int NON_SEPARATOR = 0;

  public static void writeToParcel(Parcel out, String str) {
    if (str != null) {
      out.writeInt(EXIST_SEPARATOR);
      out.writeString(str);
    } else {
      out.writeInt(NON_SEPARATOR);
    }
  }

  public static String readStringFromParcel(Parcel in) {
    int flag = in.readInt();
    if (flag == EXIST_SEPARATOR) {
      return in.readString();
    } else {
      return null;
    }
  }

  public static <T extends Parcelable> T readFromParcel(Parcel in, Class<T> cls) {
    int flag = in.readInt();
    if (flag == EXIST_SEPARATOR) {
      return in.readParcelable(cls.getClassLoader());
    } else {
      return null;
    }
  }

  public static <T extends Parcelable> void writeToParcel(Parcel out, T model) {
    if (model != null) {
      out.writeInt(EXIST_SEPARATOR);
      out.writeParcelable(model, 0);
    } else {
      out.writeInt(NON_SEPARATOR);
    }
  }

  @SuppressWarnings("unchecked")
  public static <T extends Parcelable> List<T> readListFromParcel(Parcel in, Class<T> cls) {
    int flag = in.readInt();
    if (flag == EXIST_SEPARATOR) {
      return in.readArrayList(cls.getClassLoader());
    } else {
      return null;
    }
  }

  @SuppressWarnings("unchecked")
  public static <T extends Parcelable> void writeListToParcel(Parcel out, List<T> collection) {
    if (collection != null) {
      out.writeInt(EXIST_SEPARATOR);
      out.writeParcelableArray((T[]) collection.toArray(), 0);
    } else {
      out.writeInt(NON_SEPARATOR);
    }
  }

}




Java Source Code List

io.rong.imkit.demo.BaseActivity.java
io.rong.imkit.demo.BaseApiActivity.java
io.rong.imkit.demo.BlackListActivity.java
io.rong.imkit.demo.BlackListAdapter.java
io.rong.imkit.demo.DefaultExceptionHandler.java
io.rong.imkit.demo.DemoActivity.java
io.rong.imkit.demo.DemoApplication.java
io.rong.imkit.demo.DemoContext.java
io.rong.imkit.demo.FunctionListAdapter.java
io.rong.imkit.demo.GroupListActivity.java
io.rong.imkit.demo.GroupListAdapter.java
io.rong.imkit.demo.LocationActivity.java
io.rong.imkit.demo.LoginActivity.java
io.rong.imkit.demo.MainActivity.java
io.rong.imkit.demo.ParcelUtils.java
io.rong.imkit.demo.RegisterActivity.java
io.rong.imkit.demo.TestFragment2Activity.java
io.rong.imkit.demo.TestFragmentActivity.java
io.rong.imkit.demo.UserInfoActivity.java
io.rong.imkit.demo.common.DemoApi.java
io.rong.imkit.demo.model.CustomerService.java
io.rong.imkit.demo.model.Status.java
io.rong.imkit.demo.model.User.java
io.rong.imkit.demo.parser.GsonArrayParser.java
io.rong.imkit.demo.parser.GsonParser.java
io.rong.imkit.demo.parser.JsonObjectParser.java
io.rong.imkit.demo.parser.RegisterParser.java
io.rong.imkit.demo.ui.BaseFrameLayout.java
io.rong.imkit.demo.ui.LoadingDialog.java
io.rong.imkit.demo.ui.WinToast.java