コード例 #1
0
  /** {@inheritDoc} */
  @Override
  public void writeToParcel(Parcel dest, int flags) {
    boolean[] validDataList = new boolean[MemberData.values().length];
    int validDataPos = dest.dataPosition();
    dest.writeBooleanArray(validDataList); // Placeholder for real array.

    if (mPluginId != null) {
      validDataList[MemberData.PLUGIN_ID.ordinal()] = true;
      dest.writeString(mPluginId);
    }

    if (mNetwork != null) {
      validDataList[MemberData.NETWORK.ordinal()] = true;
      dest.writeString(mNetwork);
    }

    if (mNetworkUrl != null) {
      validDataList[MemberData.NETWORK_URL.ordinal()] = true;
      dest.writeString(mNetworkUrl.toString());
    }

    if (mIconUrl != null) {
      validDataList[MemberData.ICON_URL.ordinal()] = true;
      dest.writeString(mIconUrl.toString());
    }

    if (mAuthType != null) {
      validDataList[MemberData.AUTH_TYPE.ordinal()] = true;
      dest.writeString(mAuthType);
    }

    if (mIconMime != null) {
      validDataList[MemberData.ICON_MIME.ordinal()] = true;
      dest.writeString(mIconMime);
    }

    if (mOrder != -1) {
      validDataList[MemberData.ORDER.ordinal()] = true;
      dest.writeInt(mOrder);
    }

    if (mName != null) {
      validDataList[MemberData.NAME.ordinal()] = true;
      dest.writeString(mName);
    }

    if (mCapabilities != null) {
      dest.writeInt(mCapabilities.size());
      for (IdentityCapability cap : mCapabilities) {
        cap.writeToParcel(dest, 0);
      }
    } else {
      dest.writeInt(0);
    }

    int currentPos = dest.dataPosition();
    dest.setDataPosition(validDataPos);
    dest.writeBooleanArray(validDataList); // Real array.
    dest.setDataPosition(currentPos);
  }
コード例 #2
0
  /**
   * Read Identity item from Parcel.
   *
   * @param in Parcel containing Identity information.
   */
  private void readFromParcel(Parcel in) {
    mPluginId = null;
    mNetwork = null;
    mNetworkUrl = null;
    mIconUrl = null;
    mAuthType = null;
    mIconMime = null;
    mOrder = -1;
    mName = null;
    mCapabilities = null;

    boolean[] validDataList = new boolean[MemberData.values().length];
    in.readBooleanArray(validDataList);

    if (validDataList[MemberData.PLUGIN_ID.ordinal()]) {
      mPluginId = in.readString();
    }

    if (validDataList[MemberData.NETWORK.ordinal()]) {
      mNetwork = in.readString();
    }

    if (validDataList[MemberData.NETWORK_URL.ordinal()]) {
      try {
        mNetworkUrl = new URL(in.readString());
      } catch (MalformedURLException e) {
        LogUtils.logW(
            "Identity.readFromParcel() " + "MalformedURLException on MemberData.NETWORK_URL");
      }
    }

    if (validDataList[MemberData.ICON_URL.ordinal()]) {
      try {
        mIconUrl = new URL(in.readString());
      } catch (MalformedURLException e) {
        LogUtils.logW(
            "Identity.readFromParcel() " + "MalformedURLException on MemberData.ICON_URL");
      }
    }

    if (validDataList[MemberData.AUTH_TYPE.ordinal()]) {
      mAuthType = in.readString();
    }

    if (validDataList[MemberData.ICON_MIME.ordinal()]) {
      mIconMime = in.readString();
    }

    if (validDataList[MemberData.ORDER.ordinal()]) {
      mOrder = in.readInt();
    }

    if (validDataList[MemberData.NAME.ordinal()]) {
      mName = in.readString();
    }

    int noOfCapabilities = in.readInt();
    if (noOfCapabilities > 0) {
      mCapabilities = new ArrayList<IdentityCapability>(noOfCapabilities);
      for (int i = 0; i < noOfCapabilities; i++) {
        IdentityCapability cap = IdentityCapability.CREATOR.createFromParcel(in);
        mCapabilities.add(cap);
      }
    }
  }